当放弃对 iOS 12 的支持时,仍然会收到 INStartAudioCallIntent(INStartCallIntent)

Fro*_*ing 5 swift nsuseractivity ios13

在放弃对 iOS 12 的支持时,我遇到了一个奇怪的问题。当从 AppDelegate 继续 userActivity 处理用户活动时,尽管我们放弃了 INStartAudioCallIntent 和 INStartVideoCallIntent 因为它在 iOS 13 中已弃用,但我们仍然从本机联系人卡接收上述 2 个意图。但实际上我们想要处理 INStartCallIntent。任何人都知道为什么我的调试版本是 14.6 会发生这种情况,谢谢。

Jon*_*nas 1

添加 Intent 作为应用程序扩展来处理 INStartCallIntentHandling 使我的 AppDelegate 收到 INStartCallIntent!可以这样实现:

  1. 文件>新建->目标->意图

  2. 将 INStartCallIntent 添加到支持的 Intent

  3. 像这样实现 IntentHandler (在意图扩展中):

    class IntentHandler: INExtension, INStartCallIntentHandling {
         override func handler(for intent: INIntent) -> Any {
             return self
         }
    
         func handle(intent: INStartCallIntent, completion: @escaping (INStartCallIntentResponse) -> Void) {
             let userActivity = NSUserActivity(activityType: NSStringFromClass(INStartCallIntent.self))
             let response = INStartCallIntentResponse(code: .continueInApp, userActivity: userActivity)
    
             completion(response)
         }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  4. INStartCallIntent 现在将在 AppDelegate 中调用:

    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if let intent = userActivity.interaction?.intent {
        if let intent = intent as? INStartCallIntent {
            // The correct INStartCallIntent
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)

    }