Want: I want to be able to trigger a http request on receipt of a push notification(Silent) while the application is in the background(Includes while the phone is in sleep mode).
Assumption: Push Notifications wake up application that is running in the background(Even while in sleep) https://discussions.apple.com/thread/3650066 : Offers a resolution that suggests new router but this only applies to phones that are on WiFi. I am using a cellular connection.
Attempts: I have verified that I am using the right delegate method didRecieveRemoteNotification
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
NSLog(@"Remote Notification Recieved From:\t%@", userInfo[@"requestorSessionId"]);
[_agentService handleAgentLocationRequest:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
I have attempted to log any push notification received but those don't show up if the phone is on sleep mode. (Reading Logs through iOS Console http://lemonjar.com/iosconsole/)
I have verified that notifications are working because while the app is in the foreground or in background(non-sleep mode) I am able to see the log statements.
I have added the sound playback as part of the Push Notification payload and I am able to hear the sound play when the notification is received(Sleep-Mode) but my application is never give the notification to handle.
I also have Remote Notifications enabled in the UIBackground Modes under capabilities in the Project.
Update
Realized that I was testing over local network and when the phone goes to sleep the WiFi Radio also turns off which makes connecting to local ips impossible without port forwarding.
Even with this new found discovery. I am still having problems with particular iPhones in this case an iPhone 6 that will receive the push notification for a short time span and then never receieve them again.
Thanks in advance and I will be monitoring thread to give more information as needed.
"Assumption: Push Notifications wake up application that is running in the background(Even while in sleep)".
This used to be the case with iOS7 but with iOS8 it has changed. A background push will now only be delivered to the app under certain circumstances. Apple have not stated explicitly what these circumstances exactly are but from my extensive experimentation it basically comes down to if the phone is being charged or not. There are some other variables at play (such as network type, device type, wifi enabled) but the major major major factor is whether the device is being charged or not when the push arrives.
If the phone is being charged via a direct mains power supply or indirectly by being connected by USB to a computer then the background pushes will get delivered to the app the vast majority of the time. But disconnect the phone from the power supply or USB and the background push will almost never get delivered to the app, even if the phone's batter has a 100% charge.
You can very easily test this for yourself just by sending some pushes while the phone is being charged versus while its not. BUT you must take into account that background pushes with a development build and using the sandbox environment DO NOT behave the same as background pushes with a production build and a production environment, the background pushes are actually more likely to be delivered to the app in development then they are in production so it is vital you test using a production build and Apple's production environment to see the actual results.
Note there are two steps the push delivery, the first is it needs to get delivered to the phone itself, the second is once the phone has it, it then needs to get delivered by the OS to the app. In iOS7 things such as turing on Wifi made the chances of the push getting to the phone increase. With iOS8 however even though the push is successfully being delivered to the phone, the OS is not forwarding it on to a background app if the phone isn't being charged. This means the phone gets the notification and holds on to it, sometimes for several hours, before it might forward it to the app if the phone isn't being charged.