Siri Shorcuts всегда запускает приложение - PullRequest
0 голосов
/ 12 ноября 2018

Я добавил ярлыки Siri в свой телефон, и всякий раз, когда я вызываю ярлык в Siri, он открывает приложение iOS.

Это не выполняет намерение, которое я написал.

Ниже приводится мой IntentHandler.swift

import Intents

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.

        return self
    }

}

1 Ответ

0 голосов
/ 12 ноября 2018

Я решил это, вернув экземпляр обработчика намерений.

import Intents

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.

        return ViewPointsIntentHandler()
    }

}

и добавил следующие методы в файл AppDelegate, где ViewPointsIntent - намерение ярлыка Siri.

 func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        if let intent = userActivity.interaction?.intent as? ViewPointsIntent {
            handle(intent)
            return true
        }
        return false
    }

private func handle(_ intent: ViewPointsIntent) {
        let handler = ViewPointsIntentHandler()
        handler.handle(intent: intent) { (response) in
            print("success")
        }
    }
...