Silent Push Notification in iOS 7 does not work
Solution 1
This works also and does not play a sound when it arrives:
{
aps = {
"content-available" : 1,
sound : ""
};
}
EDIT
People having this problem may want to check out this link. I have been participating in a thread on Apple's Developer forum that goes over all app states and when silent pushes are received and not received.
Solution 2
So I just came across this issue yesterday, and after trying sending a payload with a sound set to an empty string, it was still causing vibration/sound on the device. Eventually, I stumbled on a blog post from Urban Airship that suggested needing to send:
{ priority: 5 }
in the push notification, which I had never seen. After perusing Apple's docs for push notifications, I stumbled on this page:
Which indicates that priority should be set as "5" or "10", and explains:
The notification’s priority. Provide one of the following values:
10 The push message is sent immediately.
The push notification must trigger an alert, sound, or badge on the device. It is an error to use this priority for a push that contains only the content-available key.
5 The push message is sent at a time that conserves power on the device receiving it.
Ultimately, we were able to get silent push notifications working with a badge count (and I suspect you could even do the same with an alert) with the following format:
aps = {
badge = 7;
"content-available" = 1;
priority = 5;
};
Solution 3
I have tried setting an empty string as the alert attribute and it also worked:
{
aps = {
"content-available" = 1;
"alert" = "";
};
}
It seems like APNS is checking for the existence of this attributes for the purpose of validating the push payload. Interestingly, they are not checking the actual content. It seems a little bit hacky though...
Solution 4
I use the tool-Knuff send my push notification to my device.
Then,I tried these example.
They are all work!But you must set the priority 10!
So if you are not use the tool,you also note it.
examples:
- no alert,no sound
{
"aps":{
"content-available":1,
}
}
- only alert
{
"aps":{
"content-available":1,
"alert":""
}
}
- only sound
{
"aps":{
"content-available":1,
"sound":""
}
}
Solution 5
This works for me:
{
aps: {
content-available: 1
}
}
Look if you check Background fetch
checkbox in Project Capabilities
> Background Modes
evalsyrelec
Updated on July 19, 2020Comments
-
evalsyrelec almost 4 years
In the WWDC 2013's "What's New with Multitasking" presentation, there is a section about Silent Push Notifications. It seems straight forward. According to the presentation, if you send the APS payload with just the content-available set to 1, users will not be notified of the notification.
// A. This doesn't work { aps: { content-available: 1 } }
My testing shows that this does not work as no push is received. But if I include the sound attribute but exclude the alert attribute, it works (though not silent anymore).
// B. This works { aps: { content-available: 1, sound: "default" } }
However, if I change the sound attribute to play a silent audio, I can mimic a silent push.
// C. This works too. { aps: { content-available: 1, sound: "silence.wav" } }
Does anyone know:
- If this a bug?
- And if it is correct to assume that B or C is being treated as a Remote Notification (and not a bug with Silent Push where you need a sound attribute)? If so, this means it is not rate limited like Silent Pushes are... which Apple will likely fix. So I probably should not rely on it.
- What the rate limit is (N pushes every X seconds, etc)?
Thanks in advance.
Edit with more information
For A, the state of the application does not matter. Notification is never received.
It seems like B and C only work if you enclose the attributes and values in quotes, like below.
{"aps":{"content-available": 1, "sound":"silent.wav"}}
And the notification arrives in application:didReceiveRemoteNotification:fetchCompletionHandler: regardless of state.
-
SG1 over 10 yearsThanks for the link. There are multiple threads discussing this on ADC's Forums. Bottom line: there is a bug - after device restart - which an Apple rep has acknowledged should be fixed in an update (eventually).
-
evalsyrelec over 10 yearsIf the app is in the background, and if you remove the 'alert' attribute, you should receive the callback in application:didReceiveRemoteNotification:fetchCompletionHandler:
-
rjobidon over 9 yearsGreat answer Dave! A priority of 5 is allowed while "it is an error to use this priority [10] for a push that contains only the content-available key." developer.apple.com/library/ios/documentation/…
-
Foriger over 9 yearsShould be priority included in payload? IMO it is separete one byte in push you send.
-
Sandy D. over 9 yearsPriority does not get set in the payload. This gets set in the binary notification.
-
malex over 9 yearsIn iOS7 it works great even without sound/alert keys. Content-avalable is sufficient key! But in iOS8 we have really strange behavior when even we set alert key with non-empty string in addition to "content-available" : 1 we get only banner with "alert" string, but "content-available" is ignoring for some reasons
-
loretoparisi over 8 yearsThis solution with
alert=""
in the payload worked for me as well oniOS 9.0
. Thesound=""
didn't work instead. -
emem over 8 yearsI have had success with launching the app from notification with or without the added sound. Maybe, setting a sound, alert, or badge (empty or not) rises the default notification priority to 10, thus increasing its reliability. See what Apple says about pans-priority: developer.apple.com/library/ios/documentation/… The default priority is 10 (high), but it is an error to use this for push notification with only content-available key. So maybe the default is set to 5 if only the content-available key is set.
-
Stony over 7 yearsdoesn't work on iOS10. I must push something to "sound".
-
DaNLtR over 7 years@mkwon and if I want to see the alert(regular push) while in BG + invoke application:didReceiveRemoteNotification:fetchCompletionHandler: ? Tnx
-
Slav over 6 yearsWorked on iOS10 for me. But doesn't work now on iOS11
-
Evan Kirkwood over 5 yearsThe link to the Apple Developer Forum thread in the edit seems to be dead. I know this is going back a long time now, but does anyone happen have an updated link (or title of that thread)?
-
hgwhittle over 4 yearsWorked for me, iOS 13