Fro*_*ing 5 swift nsuseractivity ios13
在放弃对 iOS 12 的支持时,我遇到了一个奇怪的问题。当从 AppDelegate 继续 userActivity 处理用户活动时,尽管我们放弃了 INStartAudioCallIntent 和 INStartVideoCallIntent 因为它在 iOS 13 中已弃用,但我们仍然从本机联系人卡接收上述 2 个意图。但实际上我们想要处理 INStartCallIntent。任何人都知道为什么我的调试版本是 14.6 会发生这种情况,谢谢。
添加 Intent 作为应用程序扩展来处理 INStartCallIntentHandling 使我的 AppDelegate 收到 INStartCallIntent!可以这样实现:
文件>新建->目标->意图
将 INStartCallIntent 添加到支持的 Intent
像这样实现 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)
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)
}
| 归档时间: |
|
| 查看次数: |
823 次 |
| 最近记录: |