iOS 13 没有在后台收到 VoIP 推送通知

iOS 13 not getting VoIP Push Notifications in background

我正在 Swift 使用 CallKit 和 PushKit 开发软电话。在 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("", {[=11=] + String(format: "%02X", ) })
    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")
    }
}

谢谢。

documentation 说:

Typically, you keep the push registry object running for the duration of your app.

尝试将 voipPushResgistry 声明为 AppDelegate 的 属性,而不是 application(didFinishLaunchingWithOptions) 函数的变量。也许它可以帮助。

如果您使用 Xcode 11(和 iOS 13 SDK)构建应用程序,如果您未能向 CallKit 报告,PushKit 将不再工作。

On iOS 13.0 and later, if you fail to report a call to CallKit, the system will terminate your app. Repeatedly failing to report calls may cause the system to stop delivering any more VoIP push notifications to your app. If you want to initiate a VoIP call without using CallKit, register for push notifications using the UserNotifications framework instead of PushKit.

https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate/2875784-pushregistry

当使用 iOS 13 SDK.

编译时,您无法再通过 CallKit 接收 VoIP 通知和报告新来电

检查 ,我已经解释了可用于不应提醒新来电的通知的选项。

@mudassirzulfiqar 在 Github 上的回答(感谢他)。卸载并重新安装我的应用程序后,我收到了 voip 推送通知。现在,我将在 didReceiveIncomingPushWith 中调用 reportNewIncomingCall

I have figured out the issue, as it is stated in the official forums by Apple that not calling completion will result ban your application after 3 to 5 attempts I guess. So I think when the app get banned in 2 to 3 attempts then it stops receiving voip.

Use case: I reinstalled my application and put my application into the background and didReceiveIncomingPushWith gets called. But because i'm not using completion closure on the right time, probably again Im not going to receive voip next time. And this always work fine when app is in foreground.