共用方式為


INExtension.GetHandler(INIntent) 方法

定義

如果 是其擴充功能可以回應的一個,開發人員會覆寫這個方法以傳回處理常式物件 intent

[Foundation.Export("handlerForIntent:")]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 10, 0, ObjCRuntime.PlatformArchitecture.All, null)]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.WatchOS, 3, 2, ObjCRuntime.PlatformArchitecture.All, null)]
[ObjCRuntime.Unavailable(ObjCRuntime.PlatformName.MacOSX, ObjCRuntime.PlatformArchitecture.All, null)]
public virtual Foundation.NSObject GetHandler (Intents.INIntent intent);
abstract member GetHandler : Intents.INIntent -> Foundation.NSObject
override this.GetHandler : Intents.INIntent -> Foundation.NSObject

參數

intent
INIntent

INIntent系統收到的 。

傳回

開發人員的處理常式物件,如果 intent 不是由延伸模組處理,則 null 為 。

實作

屬性

備註

開發人員的處理常式物件必須實 IIN{Intent}Handling 作適合這個方法傳回處理常式之類型 () INIntent 的介面。 例如:

class MyExtension : INExtension
{
    override public NSObject GetHandler (INIntent intent)
    {
        if (intent is INSendMessageIntent)
        {
            return new MySendMessageHandler ();
        }
        return null;
    }
}

class MySendMessageHandler : NSObject, IINSendMessageIntentHandling
{
    public void HandleSendMessage (INSendMessageIntent intent, Action<INSendMessageIntentResponse> completion)
    {
        // ... Send a message here ...

        var activity = new NSUserActivity (nameof (INSendMessageIntent));
        var response = new INSendMessageIntentResponse (INSendMessageIntentResponseCode.Success, activity);
        completion (response);
    }
}

適用於