I am trying to react on silent push messages. I registered my app for the two background modes in my plist file.
I am sending the following json to my app:
{
"aps": {
"content-available": 1
},
"Bla": "Blub"
}
If my app is in foreground, everything works. As I am receiving the push I execute a function in my code. If my app is in background and plugged to my Mac or ac, everythings fine as well... But if I unplug my device, the device is not getting or at least my function is not called anymore...Why is that?
The way I understand that silent notifications work is that they can be sent, the system may receive them, but may not act upon them depending on different factors.
A silent notification is used to give the illusion of multi-tasking on a device that is power efficient as well. My understanding is that there are a few factors they system uses to determine whether it should pass along a silent notification to an app, these include:
In your case the silent notification is working when in the foreground because you are the foremost application. The user could be doing a task which does not involve the content right away. But the content update could be useful. For example with Facebook, I may be writing a post on a friends wall, there are new stories for my feed. It is nice to have that updated whilst I am doing something else.
For the case of being connected to your computer - The device is charging doing the background task is not going to be a drain on the device battery.
To give more details for the factors:
Network Conditions
Current Power Levels
Application Usage
User Choice
Possible Power Drain
These factors are not definitive, proven or stated from what I can tell. I am suggesting them as possible reasons based on WWDC talks, previous background task restrictions and my own assumptions. But I hope they help give an idea why your silent notifications are working in certain instances and not in others.