我在Xcode 10(iOS 12 Beta)中捐赠自定义意图时遇到问题.
我创建了一个自定义框架,它在我的主应用程序目标和我的'OrderIntent'目标之间共享.
我创建了一个.intentdefinition文件,其目标成员资格设置为我的自定义框架(下面的屏幕截图).
我在主应用程序中嵌入了"Intents Extension"和"Intents UI Extension".
我还在添加了Intents扩展(下面的截图)时创建的两个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")
}
}
}
Run Code Online (Sandbox Code Playgroud)
当用户点击应用程序中的按钮时,上面的代码会运行.
我也设置了这样的intent处理程序:
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
switch intent {
case is OrderIntent:
return OrderIntentHandler()
default:
fatalError()
}
return self
}
Run Code Online (Sandbox Code Playgroud)
而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)
}
}
Run Code Online (Sandbox Code Playgroud)
在设备上测试时,我收到以下错误:
Error Domain = IntentsErrorDomain Code = 1901"此应用程序不支持捐赠意图'OrderIntent'.请确保您有一个支持此意图的扩展名." UserInfo = {NSLocalizedDescription =此应用程序不支持捐赠意图'OrderIntent'.请确保您有一个支持此意图的扩展程序.}
我无法理解为什么应用程序不支持'OrderIntent'.
我已经在功能选项卡中启用了Siri,并请求用户等的许可.
是否还需要采取其他措施才能让我捐赠意图?
| 归档时间: |
|
| 查看次数: |
1661 次 |
| 最近记录: |