Voip Pushkit : After first push notification, app keeps running in the background

Hi,

After receiving first Voip push notification and executing some tasks (alerts, play receiving audio etc ...), the application seems to be running in the background and never stops. After that, it doesn't need a push to receive audio and play ( accept call and play audio is automatic..). I could see continuous application logs in the console log.


Initially, after application launched, logged in, active, from the console logs I could see application running. Then when phone gets locked ( app goes to background and put to sleep) the application-logs completely stops. Voip call is not received by the app. Then when a Voip Push is sent and a call is made, push-notification creates an alert and I could get the received call-audio being played out. After few seconds phone goes to sleep, but application logs keeps coming in the console-log and application seems never gets suspended. After this I could make calls and receive audio without pushes.


Can someone explain, the rational behind this behaviour?


We expect the application runs only for 30 or 30+ seconds only after receiving each push. However here app never stops running after first push.

Replies

You are talking about a debug configuration of your app, probably. The backgrounnd time is very long.

Release version will behave differently. The time is about a minute. If your app will receive pushes very often, the time in the background will become shorter. System even may stop to send you pushes if they arrive too often, let's say few times per second - after a hangred of such pushes you will need to re-start the app.

Hi Pavel,


Thanks.

Do you mean Build configuration? Yes Now it's in debug mode. However, app goes to sleep on power button press and af the a single push received, app keeps running for ever, while phone goes back to sleep in few seconds.


I will switch the Build configuration to release mode and test.

Hi Pavel,


(I'd issues in running release version and it took a while to fix them ).


I've tested with release version. Behaviour seems to be the same. After the firs push, application continues to run in the background and can receive call and play audio (automatically, while screen is still in sleep mode)


When phone is in locked (at sleep) mode after first push, and when we press the power button, I could see the red bar (background) appearing on top of the screen.

Probably I do not understand what you mean. You insist that your app in the released configuration (the App Store version) receives a VoIP push and run forever in the background?

The app receives some time in the background. Maybe it can be 2 min. If the app will receive the pushes more often the time will be shorter.

And yes, in the background your app will work fine: play audio does not make any problem - whatever allowed to do in the background.

I built app in a release build version ( we havn't released it to App Store yet) and used AdHoc provisioning profile to build ( for local test).


Steps I did,


1. Start the app, login ( so that VoIp service starts -- Login/SIP/RTP sockets created and listening...), test for a voip ptt (a voip application to receve audio automatically to the speaker without user intervention).


2. Press the power button ( or leave for while) for the phone to go to (locked) sleep mode. ( when watching console logs via XCode, we could see no log from the app, thus confirming that app is in sleep mode - suspended-or-non-active-mode)


3. Start a voip ptt call from another device, but the sleep-phone does not receive the call/audio


4. Send a VoIP-push (via APNS) to (sleep) device and start a voip ptt call. Now device receives a notification and we start to hear receiving audio from the phone speaker. Stop voip ptt call. The app's log continues to flow in the console log.


5. After 20 seconds, try another voip ptt call form the sending device, ( this time NO push sent) we can hear the audio from sleeping device (via the app). The app's log continues to flow in the console log.


6. After 1 min / 2 min 10 min/ 60 min , try voip ptt calls form the sending device, ( without push sent) we can hear the audio from sleeping device (via the app) each time. The app's log continues to flow in the console log and never stops.


And also, when I press the power button (even after 60 min), a red-bar appears on top of the screen. Which I believe, indicates app still running in the background mode.


This confirms my observation that, initially app goes to (sleep) suspended mode, when phone goes to sleep mode. But after a (single) push received, the app starts to run in background mode and never goes to sleep.


I'm trying to understand why the IOS did not suspend the app, after 1 minute after the push ?

About local ad-hoc testing still connected to Xcode - see https://developer.apple.com/library/archive/qa/qa1764/_index.html


And note that doing so can mask issues related to the watchdog timer, which may be specifically what you need to know about.


QA1764 has other suggestions, such as an archive build/test that may help with your checks.


Good luck.

It seems the problem may be when receiving 'didReceiveIncomingPushWithPayload'.....


(void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void(^)(void))completion


1. I may not call completion handler. properly:

I did have a dispatch_after() call to execute completion() after 30 seconds. However, I doubt whether this was executed after 30 secs.


2. And also, I turned on in/out audio device on reception of Push, but didn't turn it off (after 30 seconds ?).


Now I put both (completion() and audio-device-off) in one function onPushCompletion and execute it after 30 seconds.


I used the following code ( after creating a user Notification on Push)

__block AppDelegate* blocksafeSelf = self;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 30*NSEC_PER_SEC), dispatch_get_main_queue(), ^{

[blocksafeSelf onPushCompletion];});


After the above change, now the application gets suspened at ~36 seconds after the push received. This is consistant.

No app logs in console, after it suspened. Now any voip-ptt call does n't work, if no push sent, as expected.


Thanks guys