Я пытаюсь настроить собственные намерения. Я закончил с созданием "файла определения намерений", класс намерений создан Xcode и продолжен, поскольку были реализованы предопределенные намерения, при попытке с Siri он не распознает их.
Дляпример:
Эй, Сири!
Поиск фильма "Человек-паук" в приложении "Мои фильмы".
Я хочу установить "Человек-паук" в текстовом поле.
![enter image description here](https://i.stack.imgur.com/x4zqx.png)
class IntentHandler: INExtension{
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.
guard intent is MySpeechIntent else {
fatalError("Unhandled Intent error : \(intent)")
}
return MySpeechIntentHandler()
}
--------------------------------------------------
import Foundation
import Intents
class MySpeechIntentHandler: NSObject,MySpeechIntentHandling {
func handle(intent: MySpeechIntent, completion: @escaping (MySpeechIntentResponse) -> Void) {
guard intent is MySpeechIntent else{
completion(MySpeechIntentResponse(code: .failure, userActivity: nil))
return
}
print("handled")
print(intent.contentName)
completion(MySpeechIntentResponse(code: .success, userActivity: nil))
}
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
guard let intent = userActivity.interaction?.intent as? MySpeechIntent else {
print("AppDelegate: mySpeechIntent - FALSE")
return false
}
print("AppDelegate: myspeechIntent - TRUE")
print(intent)
return true
}
«contentName» - это определенный параметр, объявленный в «файле определения намерений», данные в нем должны быть словом, сказанными сэру.