Siri Intent捐赠报错:无有效快捷方式类型问题排查求助
我在Intent Handler的日志中发现了无法理解的问题,调用INInteraction.donate()时抛出错误,提示**"Cannot donate interaction with intent that has no valid shortcut types"**。
相关代码(添加参会者函数)
func addAttendee(numberToAdd: Int) -> Int { self.numberOfAttendees += numberToAdd let intent = AddAttendeeIntent() intent.suggestedInvocationPhrase = "Add People" intent.people = NSNumber(value: numberToAdd) let interaction = INInteraction(intent: intent, response: nil) interaction.donate { (error) in if error != nil { if let error = error as NSError? { self.logger.log("error occurred: \(error, privacy: .public)") } } else { self.logger.log("Add people Intent success") } } return (self.numberOfAttendees) }
错误日志
error occurred: Error Domain=IntentsErrorDomain Code=1901 "Cannot donate interaction with intent that has no valid shortcut types: <INInteraction: 0x6000002b0480> {
intent = <INIntent: 0x6000014b0510> {
};
dateInterval = <_NSConcreteDateInterval: 0x600002670da0> (Start Date) 2023-03-05 01:30:08 +0000 + (Duration) 0.000000 seconds = (End Date) 2023-03-05 01:30:08 +0000;
intentResponse =;
groupIdentifier =;
intentHandlingStatus = Unspecified;
identifier = 8E92F53E-C532-4C3A-A58A-E30E2177A227;
direction = Unspecified;
} for intent <AddAttendeeIntent: 0x600001490090> {
people = 1;
}" UserInfo={NSLocalizedDescription=Cannot donate interaction with intent that has no valid shortcut types: <INInteraction: 0x6000002b0480> {
intent = <INIntent: 0x6000014b0510> {
};
dateInterval = <_NSConcreteDateInterval: 0x600002670da0> (Start Date) 2023-03-05 01:30:08 +0000 + (Duration) 0.000000 seconds = (End Date) 2023-03-05 01:30:08 +0000;
intentResponse =;
groupIdentifier =;
intentHandlingStatus = Unspecified;
identifier = 8E92F53E-C532-4C3A-A58A-E30E2177A227;
direction = Unspecified;
} for intent <AddAttendeeIntent: 0x600001490090> {
people = 1;
}}
Intent定义检查
我确认过Intent的定义配置(截图显示配置项完整),没有发现问题。
Intent Handler代码
override func handler(for intent: INIntent) -> Any { // This is the default implementation. If you want different objects to handle different intents, // you can override this and return the handler you want for that particular intent. logger.log("\(intent)") switch intent { case is AddAttendeeIntent: return AddAttendeeIntentHandler() case is RemoveAttendeeIntent: return RemoveAttendeeIntentHandler() case is StartMeetingIntent: return StartMeetingIntentHandler() case is EndMeetingIntent: return EndMeetingIntent() case is ResetMeetingIntent: return ResetMeetingIntent() case is QuorumReachedIntent: return QuorumReachedIntent() default: fatalError("Shortcut - No handler for this intent") } }
疑问
我不清楚"无有效快捷方式类型"具体指什么。另外尝试修改Intent Handler的AddAttendee分支时,系统提示该类型不存在。请问我忽略了什么细节?
内容的提问来源于stack exchange,提问作者Michael Rowe

