微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在Swift 2.3中编译Siri扩展

我想在我的应用程序中集成Siri / Intent扩展,目前基于 Swift 2.3.我正在使用Xcode 8 beta 6版本.

该应用程序甚至无法编译,发出错误

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

示例代码

@H_502_25@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方法签名.如下面的作品.

@H_502_25@@objc (handleSendMessage:completion:) func handle(sendMessage intent: INSendMessageIntent,completion: (INSendMessageIntentResponse) -> Void) { //.. }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐