Search code examples
iosswiftcallkitpushkit

PushKit notification arriving after call has ended


I have an application that implements PushKit and CallKit. The scenario in which the problem occurs is as follow:

Device A initiates a call, sending a PushKit notification to Device B. Device B has no internet connection, and therefore does not receive the call. Device A ends the call. Device B connects to the internet after some time. Device B receives the PushKit notification that Device A sent earlier and displays CallKit Incoming Call UI.

As you can see, Device B will display CallKit Incoming Call UI even after Device A ended the call.

How to prevent Device B from receiving the incoming call?

Thanks


Solution

  • In iOS 13 you must report an incoming call before you leave the PushKit completion handler, otherwise your app will be blocked from receiving further PushKit pushes. Obviously, this is a slight problem when you have a case such as you described where the call no longer exists.

    This scenario, and others, were discussed in an Apple Developer Forums thread

    The specific advice for your case is:

    • While you must report an incoming call immediately, you are still free to decide the call has failed and tell the system later, asynchronously. To do this, call reportCallWithUUID:endedAtDate:reason:. This will tear down the incoming call UI even if the user has not answered the call.
    • If the user is particularly fast at tapping the accept call button, or if the network conditions are poor or there is otherwise a lot of latency, then you should simply wait until the necessary handshakes are complete before calling fulfill on the CXAnswerCallAction. To the user, it simply appears that the call is taking some time to connect, which is a common experience even with standard phone calls.

    • Note that the system takes a few seconds for the incoming call UI to animate in, during which the app has the opportunity to complete this handshake, so this will only have a user-visible impact if it takes a significant time for the handshake to complete.

    So, what you need to do is report the call, then when you determine that the call is no longer valid (which shouldn't take long at all), immediately end the call.