我在放弃对iOS 12的支持时遇到了一个奇怪的问题。当从AppDelegate处理用户活动时,继续userActivity,尽管我们删除了INStartAudioCallIntent和INStartVideoCallIntent,因为它在iOS 13中不推荐使用,但我们仍然从本机联系人卡收到上述两个意图。但实际上我们想处理INStartCallIntent。任何人都知道为什么我的调试版本是14.6会发生这种情况,谢谢。
添加Intent作为处理INStartCallIntentHandling的应用程序扩展,使我的AppDelegate收到INStartCallIntent!它可以这样实现:
-
文件>新建->目标->意向
-
将INStartCallIntent添加到支持的Intents
-
实现IntentHandler(在intent扩展中(如下:
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) } }
-
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 } }
}