我想在我的应用程序中集成Siri / Intent扩展,目前基于 Swift 2.3.我正在使用Xcode 8 beta 6版本. 该应用程序甚至无法编译,发出错误 Type ‘IntentHandler’ does not conform to protocol ‘INSendMessageIntentH
该应用程序甚至无法编译,发出错误
Type ‘IntentHandler’ does not conform to protocol ‘INSendMessageIntentHandling’
Protocol requires function ‘handle(sendMessage:completion:)’ with type ‘(sendMessage: INSendMessageIntent, completion: (INSendMessageIntentResponse) -> Void) -> Void’
Objective-C method ‘handleWithSendMessage:completion:’ provided by method ‘handle(sendMessage:completion:)’ does not match the requirement’s selector (‘handleSendMessage:completion:’)
即使是来自Apple的示例应用程序,UnicornChat也无法使用相同的错误进行编译.我确实将SWIFT_VERSION标志更改为是,以支持Swift 2.3
示例代码:
func handle(sendMessage intent: INSendMessageIntent, completion: (INSendMessageIntentResponse) -> Void) { let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self)) let response = INSendMessageIntentResponse(code: .Success, userActivity: userActivity) completion(response) }
这失败并出现上述错误.
任何人都知道如何让Siri在Swift 2.3中工作?
所以,这有帮助https://forums.developer.apple.com/message/174455#174455
我们需要使用Swift定义@objc方法签名.如下面的作品.
@objc (handleSendMessage:completion:) func handle(sendMessage intent: INSendMessageIntent, completion: (INSendMessageIntentResponse) -> Void) { //.. }