10

I'm developing a softphone in Swift using CallKit and PushKit. Before iOS 13, VoIP notifications were working perfectly. But after the iOS 13 update, my app isn't getting VoIP push notification when it's in background. In foreground didReceiveIncomingPushWith is called, but in background it isn't called.

How can I fix this issue?

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.

delavega66
  • 719
  • 2
  • 21
  • 34

4 Answers4

22

If you build the app with Xcode 11 (and iOS 13 SDK) PushKit won't work any longer if you fail to report to CallKit.

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

Andreas Astlind
  • 320
  • 2
  • 6
  • 3
    This should be the accepted answer. Apple says that you need to call reportNewIncomingCall function to CallKit immediately after receiving the incoming VoIP push (in the same run loop). Otherwise the app will crash on start and it will have an effect like the incoming call never arrived. Apple will stop sending VoIP pushes after a few attempts that you fail to report the new incoming call to CallKit in the same run loop as when the VoIP push arrived. – Miki Sep 29 '19 at 15:04
  • That's correct, but the question is a little bit misleading. I was aware of this iOS 13 limitation, but as far as I know, if you fail to report a call, the app will crash regardless of the fact that it was in background or in foreground. So, this make me think that this is not the correct answer. – Marco Oct 03 '19 at 07:54
  • Which means building with Xcode 10 will temporarily avoid this limitation for now? Can someone confirm this? I've already upgrade my storyboard to Xcode 11..CallKit is banned in China I need time to adopt it with UserNotifications. Appreciate any help. – steven Oct 15 '19 at 10:12
  • 7
    Any idea how what's app is still using voip notification? – Anshul Nov 12 '19 at 17:48
  • any ideal? i dont know why it not working when app in background/killed – famfamfam Sep 30 '20 at 06:57
5

Answer from @mudassirzulfiqar on Github (Thanks to him). I got voip push notification after uninstall and re-install my app. Now, I will call reportNewIncomingCall in didReceiveIncomingPushWith.

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.

Community
  • 1
  • 1
delavega66
  • 719
  • 2
  • 21
  • 34
  • 1
    Thanks! that works for me too. PushKit actually has two different versions of "didReceiveIncomingPushWith" method, I was previously using the method without completion whereas using a method with completion handler worked for me. Thanks again :) – Rishabh May 08 '20 at 02:51
  • @Rishabh can you share some more info about the 2 versions and why it matter? – AleksandarT Sep 20 '20 at 20:06
  • @AleksandarT check out below link https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate/1614492-pushregistry Actually, Apple just deprecated the first version, now we need to use the one with completion, here completion block is to notify that our process is done and we report the call. – Rishabh Oct 13 '20 at 11:11
  • 1
    Correct answer! – Andreas Pardeike Jan 18 '21 at 19:19
3

You can no longer receive a VoIP notification and not report a new incoming call through CallKit, when compiling with iOS 13 SDK.

Check this other question, I've explained the options you can use for notifications that should not alert for new incoming calls.

Gabriel Gava
  • 181
  • 8
pepsy
  • 1,260
  • 11
  • 13
0

The documentation says:

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

Try to declare voipPushResgistry as a property of the AppDelegate, instead of a variable of the application(didFinishLaunchingWithOptions) function. Maybe it could help.

Marco
  • 1,095
  • 1
  • 7
  • 16