del*_*a66 4 iphone pushkit callkit ios13 xcode11
我正在使用CallKit和PushKit在Swift中开发软电话。在iOS 13之前,VoIP通知运行良好。但是,在iOS 13更新之后,我的应用程序在后台运行时没有收到VoIP推送通知。在前台didReceiveIncomingPushWith被调用,但在后台不被调用。
如何解决此问题?
码
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")
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢。
小智 8
如果您使用Xcode 11(和iOS 13 SDK)构建应用程序,则如果您无法向CallKit报告,则PushKit将不再起作用。
在iOS 13.0和更高版本上,如果您无法报告对CallKit的呼叫,则系统将终止您的应用程序。反复未能报告呼叫可能会导致系统停止向您的应用传递更多VoIP推送通知。如果要在不使用CallKit的情况下发起VoIP呼叫,请使用UserNotifications框架而不是PushKit注册推送通知。
https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate/2875784-pushregistry
来自Github 上的@mudassirzulfiqar 的回答(感谢他)。卸载并重新安装我的应用程序后,我收到了 voip 推送通知。现在,我会打电话给reportNewIncomingCall在didReceiveIncomingPushWith。
我已经解决了这个问题,正如 Apple 在官方论坛中所说的那样,我猜不调用完成将导致在 3 到 5 次尝试后禁止您的应用程序。所以我认为当应用程序在 2 到 3 次尝试中被禁止时,它就会停止接收 voip。
用例:我重新安装了我的应用程序并将我的应用程序置于后台并调用 didReceiveIncomingPushWith。但是因为我没有在正确的时间使用完成关闭,所以我下次可能不会再收到 voip。当应用程序处于前台时,这总是正常工作。