我嘗試使用 Shortcuts 應用程式運行兩個意圖。
這是我跑過的測驗IntentHandler:
這有效:
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any? {
guard intent is CarIDIntent else {
return .none
}
return AccessTokenIntentHandler()
}
}
這有效:
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any? {
guard intent is AccessTokenIntent else {
return .none
}
return AccessTokenIntentHandler()
}
}
這不起作用:
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any? {
guard intent is AccessTokenIntent else {
return .none
}
guard intent is CarIDIntent else {
return .none
}
return AccessTokenIntentHandler()
}
}
我在這里做錯了什么?它們都被添加到Intents.intentdefinition檔案中。
uj5u.com熱心網友回復:
您可以嘗試使用開關盒,但由于您沒有提供有關錯誤告訴您的任何資訊,因此很難找到確切的解決方案。嘗試這個:
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any? {
switch intent {
case is AccessTokenIntent:
print("Access Token")
case is CarIDIntent:
print("Car ID")
default:
return .none
}
return AccessTokenIntentHandler()
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/524213.html
標籤:IOS迅速代码
