I'm testing push notifications with content-available=1, and they don't seem to be delivered to the app in the background unless on Wi-Fi.
I have a simple log statement at the beginning of the push notification handler:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^) (UIBackgroundFetchResult))completionHandler {
NSLog(@"Notification received: %@", userInfo);
completionHandler(UIBackgroundFetchResultNewData);
}
Here is my test:
- Run the app, then press the home button to put the app in the background.
- Send a push notification with content-available=1
- Watch console logs
On Wi-Fi, the console log shows the notification. If I go to Settings and turn off Wi-Fi, switching to 4G, notifications no longer appear in the log (although they do slide in at the top of the screen, so I know they are being delivered).
There are no crash logs, and the notification is logged if I manually tap on it. Furthermore, this problem does NOT occur if I am debugging the app in Xcode. (i.e., if I am debugging in Xcode, the app will receive the notification in the background on 4G). Has anyone else experienced this behavior? Or am I doing something wrong?
EDIT: To be specific: according to my tests, if the following conditions are true, then the remote notification delegate method above will not be called:
- App is running in the background
- Phone is on LTE network, not connected to Wi-Fi
- App is NOT running in the Xcode debugger
- Notification with content-available=1 is received by the phone
However if condition 2 is removed (i.e., the phone is connected to Wi-Fi), then the handler will be called.
didReceiveRemoteNotification: fetchCompletionHandler:
method? Are you taking more than 30 seconds in this method? Are you returning a correct value to the completion handler. Is it perhaps a problem with your LTE carrier's network? I have tested successfully in the background although I needed a phone restart for it to work reliably – Rhythmical