我正在使用 CallKit 和 PushKit 在 Swift 中开发软件电话。在 iOS 13 之前,VoIP 通知运行良好。但在 iOS 13 更新后,我的应用程序在后台时无法收到 VoIP 推送通知。在前台didReceiveIncomingPushWith
被调用,但在后台它没有被调用。
我该如何解决这个问题?
Code
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
print("\(#function)")
let voipPushResgistry = PKPushRegistry(queue: nil)
voipPushResgistry.delegate = self
voipPushResgistry.desiredPushTypes = [PKPushType.voIP]
return true
}
func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
print("\(#function) token invalidated")
}
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {
let deviceToken = credentials.token.reduce("", {$0 + String(format: "%02X", $1) })
print("\(#function) token is: \(deviceToken)")
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
print("\(#function)")
print("It worked..")
if type == .voIP {
print("Uygulama aktif")
}
}
Thanks.
如果您使用 Xcode 11(和 iOS 13 SDK)构建应用程序,如果您无法向 CallKit 报告,PushKit 将不再工作。
在 iOS 13.0 及更高版本上,如果您无法向 CallKit 报告呼叫,
系统将终止您的应用程序。多次不报告电话可能会
导致系统停止发送更多 VoIP 推送通知
到您的应用程序。如果您想发起 VoIP 呼叫而不使用
CallKit,使用 UserNotifications 注册推送通知
框架而不是 PushKit。
https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate/2875784-pushregistry
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)