I have this problem regarding APNS in my iPad 2 running iOS 8.1 . I searched on Google for a few days and tried every solution that I can find. However I cant seem to solve this problem.
What I did:
What I want to do:
I want to perform network request when I receive the APNS in background. I believe I can handle that part well using beginBackgroundTaskWithExpirationHandler and stuff. However, going down the investigation I found that the problem is due to didReceiveRemoteNotification:fetchCompletionHandler not been run when app is in background state.
Problem:
didReceiveRemoteNotification:fetchCompletionHandler can trigger when app is in foreground. But it is ONLY triggered in background when xcode is still debugging the app. Which means if I unplug the cable (the debugging session is over), it cannot trigger anymore. Same thing if I replug it back in. No response.
However, at the same time, I can still receive APNS with alert body and sound (although the method is still not triggered) as I see in the Device Log.
I tried every combination of "silent" push notification: sound = "", alert = "", etc. But nothing seems to work. Any help from the pros here?
Thank you.
Double check that Background App Refresh is turned on. I ran into this for a while after turning it off while traveling.
Also, you shouldn't need to use a background task inside of the didReceiveRemoteNotification:fetchCompletionHandler
as it is already running in the background. Just make sure to call the appropriate completion handler when you're done with your network request.
Finally, didReceiveRemoteNotification:fetchCompletionHandler
will not be called on a regular (non-silent) notification because regular notifications do not wake your app and execute code.
EDIT: Another weird obscure thing to check is the priority in the notification frame data - link to Apple Documentation - command F for 'priority' for the details. When I was doing this my Ruby gem that built the notification was using 10 by default, which is supposedly not allowed if you are only using 'content-available' and nothing else. Things got busy at work and I never got to test this using a priority of 5, but it may help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With