【发布时间】:2018-11-21 20:19:12
【问题描述】:
我在 Xcode 10(iOS 12 Beta)中捐赠自定义 Intent 时遇到问题。
我创建了一个自定义框架,在我的主应用目标和我的“OrderIntent”目标之间共享。
我创建了一个 .intentdefinition 文件,其中目标成员资格设置为我的自定义框架(下面的屏幕截图)。
我在主应用程序中嵌入了“意图扩展”和“意图 UI 扩展”。
我还在添加意图扩展时创建的两个 info.plist 文件中将“OrderIntent”添加到 NSExtension->NSExtensionAttributes->IntentsSupported(截图如下)。
我正在尝试像这样捐赠意图:
INPreferences.requestSiriAuthorization { (status) in
if status != INSiriAuthorizationStatus.authorized {return}
let orderIntent = OrderIntent()
orderIntent.product = "Test product"
orderIntent.quantity = 2
let interaction = INInteraction(intent: customIntent, response: nil)
interaction.donate { (error) in
if error != nil {2
if let error = error as NSError? {
print(error)
}
} else {
print("success")
}
}
}
当用户点击应用中的按钮时,上面的代码就会运行。
我还设置了这样的意图处理程序:
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
switch intent {
case is OrderIntent:
return OrderIntentHandler()
default:
fatalError()
}
return self
}
OrderIntentHandler 是这样的:
public class OrderIntentHandler: NSObject, OrderIntentHandling {
public func handle(intent: OrderIntent, completion: @escaping (OrderIntentResponse) -> Void) {
let orderIntentResponse = OrderIntentResponse(code: OrderIntentResponseCode.success, userActivity: nil)
completion(orderIntentResponse)
}
public func confirm(intent: OrderIntent, completion: @escaping (OrderIntentResponse) -> Void) {
let response = OrderIntentResponse(code: OrderIntentResponseCode.ready, userActivity: nil)
completion(response)
}
}
在设备上测试时,我收到以下错误:
Error Domain=IntentsErrorDomain Code=1901 “此应用程序不支持捐赠意图 'OrderIntent'。请确保您有支持此意图的扩展程序。” UserInfo={NSLocalizedDescription=此应用程序不支持捐赠意图“OrderIntent”。请确保您有支持此意图的扩展程序。}
我不明白为什么应用程序不支持“OrderIntent”。
我已经在功能选项卡中启用了 Siri,并请求了用户等的许可。
是否需要采取任何其他步骤才能让我捐赠意图?
【问题讨论】: