ios – SiriKit,如何显示开始锻炼意图的响应?

前端之家收集整理的这篇文章主要介绍了ios – SiriKit,如何显示开始锻炼意图的响应?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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))
    }
}

Apple文档说:

enter image description here

Siri打开应用程序,但我需要显示IntentUI的UI.这该怎么做?

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

enter image description here

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
    }
}

基于this教程,它确实可能.

enter image description here

解决方法

虽然Apple说 here

You can provide an Intents UI extension if you are supporting intents in the following domains:
Messaging
Payments
Ride booking
Workouts

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

请查看INSENTMessageIntentResponseCode以了解INSENTMessageIntentHandling:

public enum INSendMessageIntentResponseCode : Int {


    case unspecified

    case ready

    case inProgress

    case success

    case failure

    case failureRequiringAppLaunch

    case failureMessageServiceNotAvailable
}

INStartWorkoutIntentHandling的INStartWorkoutIntentResponse和INStartWorkoutIntentResponse:

public enum INStartWorkoutIntentResponseCode : Int {


    case unspecified

    case ready

    case continueInApp

    case failure

    case failureRequiringAppLaunch

    case failureOngoingWorkout

    case failureNoMatchingWorkout
}

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

猜你在找的iOS相关文章