The purpose of "Content-available" in Push Notification Json?
Asked Answered
K

3

25

The purpose is to send push notification with only badge value & nothing else (no banner).

I integrated parse sdk to test push notification & send this push notification

{
"alert" :"",
"badge" :"787",
"Content-available" : "1",
"sound" : ""
}

So the push notification got send when app is in background, foreground & when app is killed. The purpose to wipe some data on arrival of push notification with badge valve 78 got succeeded. I send same notification with "Content-available" : "1" removed but everything worked fine as earlier.

My understanding on "Content-available" was that putting it's value to 1 will allow push notification with no alert value.

So I am confused or I am missing something to know the meaning of "Content-available" in this push notification JSon.

Thanks

Karinkarina answered 5/1, 2015 at 10:30 Comment(1)
Also See here. For Silent notifications you MUST always have it set to 1. For Remote Notifications you don't need it...unless you want your remote notification to also download something in the backgroundCancroid
B
19

If you provide this key with a value of 1, (if user opens you app is in background or resumed) the application:didReceiveRemoteNotification:fetchCompletionHandler: will be called.

According to RemoteNotifications Programming content-available definition is

Provide this key with a value of 1 to indicate that new content is available. Including this key and value means that when your app is launched in the background or resumed, application:didReceiveRemoteNotification:fetchCompletionHandler: is called.

(Newsstand apps are guaranteed to be able to receive at least one push with this key per 24-hour window.)

Behead answered 5/1, 2015 at 10:32 Comment(9)
My app is not newsstand app & can i implement this feature for my app? Thanks @Midhun (Sorry i like your answer but can't up vote due to low points)Karinkarina
@NandkishorChaudhari: It's for all app not for Newsstand app, newstand app have that special case.Behead
@NandkishorChaudhari: I have added more info in my answer, hope it helps youBehead
So it is always good to include @"Content-available" in push notification JSON. Does it have any drawbacks? @Thanks againKarinkarina
@NandkishorChaudhari: If you need to do some downloading or some process when a notification arrives, it's better to include that else don't include that key.Behead
Thanks @Midhun, I want push notification to be listen even when app is closed or is in background, so content -available is playing good role in this case. Also Does iTunes team will reject the app for push notification with only badge value & no alert or sound or due to the usage purpose of conten0available? Please suggest on this.Karinkarina
Alert and Sound fields not mandatory. For content usage you need to check the documentation. I don't think they will reject your app due to that.Behead
What happens if the app is in terminated state ? I need to call application:didReceiveRemoteNotification:fetchCompletionHandler: when the app is in terminated state.Oosphere
@VinothVino Yes, that method will be called even when your app is terminated.Behead
N
26

TL;DR:

  • "content-available" : 0: The default; your application won't be notified of the delivery of the notification unless the app is in the foreground.
  • "content-available" : 1: your application will be notified of the delivery of the notification if it's in the foreground or background (the app will be woken up).

The only time you need to use "content-available" : 1 is for background update notifications:

Background update notifications improve the user experience by giving you a way to wake up your app periodically so that it can refresh its data in the background. When apps do not run for extended periods of time, their data can become outdated. When the user finally launches the app again, the outdated data must be replaced, which can cause a delay in using the app. A background update notification can alert the user or it can occur silently.

However, this does NOT always mean that this notification will be invisible to the user:

If there are user-visible updates that go along with the background update, you can set the alert, sound, or badge keys in the aps dictionary, as appropriate.

By default, "content-available" is set to 0. These "regular" notifications do not immediately notify the app UNLESS the app is in foreground. Instead, these "regular" notifications notify the app when a user taps on them or has selected an option via a "Haptic Touch" on the notification.

Background update notifications are delivered to application(_:didReceiveRemoteNotification:fetchCompletionHandler:):

Unlike the application(_:didReceiveRemoteNotification:) method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background.

Note: there's a key distinction between "your application" and "the device:" the device will show the notification if the payload requests it to be shown, but this doesn't always mean that "your application" will be notified on the delivery of this notification (aka "your application" code will run). That's where "content-available": "1" comes in: "your application" will always be notified unless its been terminated.

Ninnetta answered 18/1, 2021 at 15:38 Comment(0)
B
19

If you provide this key with a value of 1, (if user opens you app is in background or resumed) the application:didReceiveRemoteNotification:fetchCompletionHandler: will be called.

According to RemoteNotifications Programming content-available definition is

Provide this key with a value of 1 to indicate that new content is available. Including this key and value means that when your app is launched in the background or resumed, application:didReceiveRemoteNotification:fetchCompletionHandler: is called.

(Newsstand apps are guaranteed to be able to receive at least one push with this key per 24-hour window.)

Behead answered 5/1, 2015 at 10:32 Comment(9)
My app is not newsstand app & can i implement this feature for my app? Thanks @Midhun (Sorry i like your answer but can't up vote due to low points)Karinkarina
@NandkishorChaudhari: It's for all app not for Newsstand app, newstand app have that special case.Behead
@NandkishorChaudhari: I have added more info in my answer, hope it helps youBehead
So it is always good to include @"Content-available" in push notification JSON. Does it have any drawbacks? @Thanks againKarinkarina
@NandkishorChaudhari: If you need to do some downloading or some process when a notification arrives, it's better to include that else don't include that key.Behead
Thanks @Midhun, I want push notification to be listen even when app is closed or is in background, so content -available is playing good role in this case. Also Does iTunes team will reject the app for push notification with only badge value & no alert or sound or due to the usage purpose of conten0available? Please suggest on this.Karinkarina
Alert and Sound fields not mandatory. For content usage you need to check the documentation. I don't think they will reject your app due to that.Behead
What happens if the app is in terminated state ? I need to call application:didReceiveRemoteNotification:fetchCompletionHandler: when the app is in terminated state.Oosphere
@VinothVino Yes, that method will be called even when your app is terminated.Behead
F
1

Short answer: for me I just used "content_available" : "1", or "content_available" : true for resume the background/quit modes in iOS. Notice in my case it's underscore and not hyphen separated.

In my specific scenario my app was made in react-native and I have used https://rnfirebase.io for push notifications

Here a complete explanation of this: https://rnfirebase.io/messaging/usage#data-only-messages

in IOS content_available" : "1

equivalent in Android priority: 'high',

In both cases the background message will invoke the onMessage() method when the app is resumed from background, so the program can run some specific code from there.

Here a sample of sending a push notification using CURL:

#curl -H "Content-type: application/json" -H "Authorization:key=#MyAuthHashCode#" -X POST -d '{ "to": "/topics/#thetopicnumber#","notification": { "title": "msg for topic", "body": "bodytext", "content_available": "true" }}' https://fcm.googleapis.com/fcm/send

Felipe answered 11/8, 2020 at 17:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.