App is only able to receive VoIP when in foreground, adhoc build

Hi folks,

I am developing the app which is about to receive voip push to initiate video call in wkwebkit (the call itself is being processed on the webpage and php backend, using agora engine).

My issue is: app was working perfectly with sandbox, however, when moved to production build with adhoc profile, for testing purposes, I found

  • VoIP pushes are working OK in foreground
  • VoIP pushes are not working at all if app is in background or not started.

When I checked device logs (the one I am calling to), I can't see no app activity in it, as soon as the callee app is not in foreground mode. If it is in foreground, again, all is fine and works as a charm.

All the integration is properly done with CallKit: I am reporting each and every push I receive as an incoming call with the variety of statuses, no push is unhandled / unreported. Just in case, I was trying to reinstall the app multiple times, but still the issue is here.

I thought it can be the distribution certificate, voip certificate, keys or provisioning profile issue - but the fact it works fine in foreground makes me quite confused.

I am testing it with 2 devices, one is iPhone 12 (iOS 15.2) with SIM in it, other one is iPhone 8 (iOS 14.7) with no SIM installed. Build is performed with XCode 13.1, on M1 Mac. Not sure it is important - just trying to share as much info as I can.

Any advice is highly appreciated, because I am lost a bit and have no idea of what's wrong, or what needs to be checked/where to dig at first?

Answered by AndreyLesnykh in 705454022

Answering my own question.

When the push is received, I am checking for my call id to be valid with backend. It is obviously async, and it takes too long from background to handle, therefore iOS considering my app as "not reported the call in time".

I am not sure how do I manage the situation yet, but as for the issue itself - it is exactly because of my server call. Just commenting it out solved the issue completely.

TWIMC, if you're facing the same - check if you have any calls using async / closures in your PushRegistry didReceiveIncomingPushWith function code. It may help you to sort the issue out.

UPD: after doing some research, I was able to find out more:

  1. My app is reporting a crash of a below kind, if called while being in background or not started

Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Triggered by Thread: 0

Application Specific Information: abort() called

Last Exception Backtrace: 0 CoreFoundation 0x180bd50fc __exceptionPreprocess + 220 1 libobjc.A.dylib 0x19940fd64 objc_exception_throw + 60 2 Foundation 0x18248f3ac _userInfoForFileAndLine + 0 3 PushKit 0x1b3a53d80 -[PKPushRegistry _terminateAppIfThereAreUnhandledVoIPPushes] + 192 4 libdispatch.dylib 0x180847670 _dispatch_client_callout + 20 5 libdispatch.dylib 0x1808568c4 _dispatch_lane_barrier_sync_invoke_and_complete + 56 6 PushKit 0x1b3a52ee0 __73-[PKPushRegistry voipPayloadReceived:mustPostCall:withCompletionHandler:]_block_invoke + 540 7 libdispatch.dylib 0x180845924 _dispatch_call_block_and_release + 32 8 libdispatch.dylib 0x180847670 _dispatch_client_callout + 20 9 libdispatch.dylib 0x180855b70 _dispatch_main_queue_callback_4CF + 944 10 CoreFoundation 0x180b8dd84 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 16 11 CoreFoundation 0x180b47f5c __CFRunLoopRun + 2540 12 CoreFoundation 0x180b5b468 CFRunLoopRunSpecific + 600 13 GraphicsServices 0x19c6e638c GSEventRunModal + 164 14 UIKitCore 0x1834fd088 -[UIApplication _run] + 1100 15 UIKitCore 0x18327b958 UIApplicationMain + 2092 16 Doctor 0x102eae2c8 main + 25288 (_hidden#331:18) 17 dyld 0x10315daa4 start + 520

  1. My app never reports crashes and it works ok while in foreground.

I do suspect strongly it is crashing because of it - 3 PushKit 0x1b3a53d80 -[PKPushRegistry _terminateAppIfThereAreUnhandledVoIPPushes] + 192

Still, it is not clear for me.

First of all, if I have a fault with incoming calls reporting somewhere in my app logic, it presumably will fail whenever it is on fore- or background, because it should (?) be working the same way. It is sitting in the same func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void)

Or, should I handle it somehow specifically? Is it the case that didReceiveIncomingPushWith payload is to be managed in some special way along with my app entering foreground? I found to reference to it from app docs.

Can anyone please help me with it?

Accepted Answer

Answering my own question.

When the push is received, I am checking for my call id to be valid with backend. It is obviously async, and it takes too long from background to handle, therefore iOS considering my app as "not reported the call in time".

I am not sure how do I manage the situation yet, but as for the issue itself - it is exactly because of my server call. Just commenting it out solved the issue completely.

TWIMC, if you're facing the same - check if you have any calls using async / closures in your PushRegistry didReceiveIncomingPushWith function code. It may help you to sort the issue out.

App is only able to receive VoIP when in foreground, adhoc build
 
 
Q