如何在您的ios应用中添加Intents扩展程序
答案 0 :(得分:2)
它有一个内置的模板,虽然我承认它需要一些工作。
这将创建两个新组:YourExtension和YourExtensionUI。如果您打开YoureExtension组,您将看到IntentHandler.swift,其中包含一些用于处理锻炼的示例代码。如果您刚开始使用,我建议完全放弃该代码,因为它的时间比它需要的时间长。
这是一个让你开始的更简单的例子:
class IntentHandler: INExtension, INSendMessageIntentHandling {
override func handler(for intent: INIntent) -> AnyObject {
// 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.
return self
}
func handle(sendMessage intent: INSendMessageIntent, completion: (INSendMessageIntentResponse) -> Void) {
print("Send message: " + (intent.content ?? "No message"))
let response = INSendMessageIntentResponse(code: .success, userActivity: nil)
completion(response)
}
}
I wrote about this, and other iOS 10 features, in more detail here.