【问题标题】:SiriKit, How to display response for start Workout Intent?SiriKit,如何显示开始锻炼意图的响应?
【发布时间】:2016-12-08 18:36:23
【问题描述】:

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 文档说:

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

基于this 教程确实可以。

【问题讨论】:

  • 只是为了确保您的 Info.plist 中是否有 NSExtensionMainStoryboard 的 MainInterface 值?
  • 是的,它嵌套在NSExtension 键中,它包含在我的IntentTimerUI 扩展中,不适用于IntentTimer
  • IntentsSupported 键怎么样?
  • 是的,它嵌套在NSExtensionAttributes 中:IntentTimerIntentTimerUI
  • 尝试改成INStartWorkoutIntent only

标签: ios swift siri sirikit


【解决方案1】:

虽然苹果说here

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

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

INSentMessageIntentHandling请看INSendMessageIntentResponseCode

public enum INSendMessageIntentResponseCode : Int {


    case unspecified

    case ready

    case inProgress

    case success

    case failure

    case failureRequiringAppLaunch

    case failureMessageServiceNotAvailable
}

INStartWorkoutIntentResponseINStartWorkoutIntentHandling

public enum INStartWorkoutIntentResponseCode : Int {


    case unspecified

    case ready

    case continueInApp

    case failure

    case failureRequiringAppLaunch

    case failureOngoingWorkout

    case failureNoMatchingWorkout
}

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

【讨论】:

  • 我也面临同样的问题,你的意思是不能为 Workout Domain 添加 IntentUI 吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多