iOS 13没有在后台获取VoIP推送通知

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

  • 知道什么应用程序仍在使用 voip 通知吗? (7认同)
  • 这应该是公认的答案。Apple 表示,您需要在收到传入 VoIP 推送后立即向 CallKit 调用 reportNewIncomingCall 函数(在同一运行循环中)。否则应用程序将在启动时崩溃,并且会产生类似来电从未到达的效果。如果您尝试几次未能在与 VoIP 推送到达时相同的运行循环中向 CallKit 报告新来电,Apple 将停止发送 VoIP 推送。 (4认同)

del*_*a66 7

来自Github 上的@mudassirzulfiqar 的回答(感谢他)。卸载并重新安装我的应用程序后,我收到了 voip 推送通知。现在,我会打电话给reportNewIncomingCalldidReceiveIncomingPushWith

我已经解决了这个问题,正如 Apple 在官方论坛中所说的那样,我猜不调用完成将导致在 3 到 5 次尝试后禁止您的应用程序。所以我认为当应用程序在 2 到 3 次尝试中被禁止时,它就会停止接收 voip。

用例:我重新安装了我的应用程序并将我的应用程序置于后台并调用 didReceiveIncomingPushWith。但是因为我没有在正确的时间使用完成关闭,所以我下次可能不会再收到 voip。当应用程序处于前台时,这总是正常工作。