4

IntentHandler类:

import Intents

class IntentHandler: INExtension, INStartWorkoutIntentHandling {

    public func handle(startWorkout intent: INStartWorkoutIntent, completion: @escaping (INStartWorkoutIntentResponse) -> Void) {

        let userActivity = NSUserActivity(activityType: NSStringFromClass(INStartWorkoutIntent.self))
        let response = INStartWorkoutIntentResponse(code: .continueInApp, userActivity: userActivity)
        completion(response)
    }

    //MARK: - INStartWorkoutIntentHandling

    func confirm(startWorkout intent: INStartWorkoutIntent, completion: @escaping (INStartWorkoutIntentResponse) -> Void) {

        completion(INStartWorkoutIntentResponse(code: .continueInApp, userActivity: nil))
    }
}

苹果文档说:

在此处输入图像描述

Siri 打开应用程序,但我需要从 IntentUI 显示 UI。这个怎么做?

换句话说:如何准备显示响应、加载意图 UI 扩展、准备界面并在代码中显示?

在此处输入图像描述

IntentViewController类:

import IntentsUI

class IntentViewController: UIViewController, INUIHostedViewControlling {

    //MARK: - INUIHostedViewControlling

    func configure(with interaction: INInteraction!, context: INUIHostedViewContext, completion: ((CGSize) -> Void)!) {

        if let completion = completion {
            completion(self.desiredSize)
        }
    }

    var desiredSize: CGSize {
        return self.extensionContext!.hostedViewMaximumAllowedSize
    }
}

基于教程,这确实是可能的。

在此处输入图像描述

4

1 回答 1

1

虽然苹果在这里说:

如果您支持以下领域中的意图,则可以提供意图 UI 扩展:
消息传递
付款
乘车预订
锻炼

我认为这是完全不可能的,因为负责开放 UI 的响应并没有为此做好准备:

INSendMessageIntentResponseCode请查看INSentMessageIntentHandling

public enum INSendMessageIntentResponseCode : Int {


    case unspecified

    case ready

    case inProgress

    case success

    case failure

    case failureRequiringAppLaunch

    case failureMessageServiceNotAvailable
}

和:INStartWorkoutIntentResponse_INStartWorkoutIntentHandling

public enum INStartWorkoutIntentResponseCode : Int {


    case unspecified

    case ready

    case continueInApp

    case failure

    case failureRequiringAppLaunch

    case failureOngoingWorkout

    case failureNoMatchingWorkout
}

对于第二个,只有.continueInApp,这正是这里发生的事情,与存在的第一个相反:.success.inProgress

于 2016-12-23T19:12:33.700 回答