I'm implementing the new background push notification system with:
apn-push-type=background
apns-priority=5
in the request header.
If I close the app the notification is delivered and the device doesn't throttle it (as per documentatiuon we can use few of this push or the device throttle them not forwarding them to the app).
If i force quit the app the app awakens and process the push notification.
After a reboot the notification is throttled and there is no way to make the app receive it. Is there something more I should add to my notification payload or header?
Currently the payload is like
{
"aps":{
"content-available": 1
}
... // other data which the app process
}
Related
I am trying to receive a notification in the background to process information in my App when it is in Foreground, Background or Closed. I don't want to receive the Alert.
I have tried to do it without placing the Title and Body at the time of shipment, only Custom Data.
How could I receive this information without using an alert, regardless of the status of the App?
A silent push notification or some might call it background notification is a notification that does not trigger any alert or sound. It wakes up your app and allows you to perform any non-UI related operations in the background.
Sample payload for a background notification:
{ "aps" : { "content-available" : 1 }, "acme1" : "bar","acme2" : 42 }
You need to add “Background Modes” and “Push Notifications” capabilities in Xcode in order for your app to be able to receive a silent push notification.
Points to note:
You can only test push notifications in a real iOS device. iOS
simulator will not be able to receive any push notifications.
The background operation triggered by a silent push notification
will have roughly 30 seconds of execution time.
Silent push notifications will not work when the device is in Low
Data Mode.
Apple guideline for this topic to refer in more details.
I just took a look at Is Silent Remote Notifications possible if user has disabled push for the app?.
It basically says the Silent Notifications disregard notification settings for user. It then says:
Users still have the ability to switch off your app’s ability to
process a “silent push” by means of the “Background App Refresh”
control. Even though Apple Push Notification service (APNs) will
deliver a push marked “content-available” to your phone, the OS will
not wake up your app to receive it, effectively dropping it on the
floor.
This is confusing to me. I want to make silent notifications go out only while the app is open, to update state of the app while in use only. So I wouldn't care if background app refresh is off because I wouldn't need to "wake up [my] app to receive it".
Secondarily Silent push notifications only delivered if device is charging and/or app is foreground talks about needing to have your phone plugged in to receive these notifications.
Both questions are from iOS 8, which is quite a ways back. Do they hold up all this time?
My answers are based on observation and my work on the apple notification.
Before iOS 13
Silent notification is not received even if notification is force killed by the user even if the background app refresh is on. Silent push received in case of foreground, background or killed by iOS
After iOS 13
Silent notification are received always if background app refresh is on.But if background app refresh is off silent push received only in foreground and background case.
If you want to only send silent push in foreground or background you should not add background mode in capability in Xcode. So it will receive only when the application is in the foreground or background
Can FCM silent notification start up a closed iOS app?
Request Type: POST
Request URL: https://fcm.googleapis.com/fcm/send
Request Headers:
Authorization -> key=MY_KEY
Content-Type -> application/json
Request Body:
{
"to": "/topics/my_topic",
"content_available": true,
"data": {
"contentAvailable": 1
},
"priority": 10
}
However, this payload does not start up my iOS app if the user closes it.
How to make the iOS to start my app whenever a silent notification is received?
It's the expected behavior to not launch the app. I mean why should it? The user for some reason has decided to kill the app. They don't want battery or bandwidth getting used for it anymore!
From documentation.
Use this method to process incoming remote notifications for your app.
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. In addition, if you enabled the remote notifications
background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again
For non-silent notifications. They would get delivered to the device. But not to the app.
If you force-quite your Whatsapp on your iPhone and your mother sends you a message, then your iPhone would show it among its notifications. However it won't trigger any of your AppDelegate methods. AppDelegate methods are only triggered if the app is not user terminated.
I have a problem. When my App is Terminated by the user, push notifications are not detected by the application. The push notification is sent with content_available = true.
What should I do?
This is default system behaviour. If you Application is terminated by the user (from the App switcher), Silent Push Notifications (content_available = true) will not wake the Application, i.e. Application:didreceiveremotenotification will not be called.
If you want the user to be notified, do not send a Silent Push Notification. Send a normal push notification which will show up in the user's notification tray.
That is the way how it works on iOS.
If you app is not running at all, your app receive no push notifications at all. Only if the user swipe over one of your push notifications on the lock screen or the notification center your app will be started and you will be notified that your app was started because of the push message.
If you app is in the background, you actually can handle push notifications by enabling "run in background" support.
I'm talking iOS9 and earlier here. Not sure if the behaviour has been changed in iOS10. But if you are coming from Android then you have to accept that push notification handling works completely different on iOS than on Android.
Sending the notification with the content_available as disabled. content_available = 0
The content_available field is used for sending silent push notifications to process in the background and will not display as a notification.
See documentation : https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH107-SW6
Hope this helps,
DT
Make sure that in your push notification payload you are adding priority:"high". It will ensure that your app will receive a Push Notification in background or closed mode.
{
"to" : "/topics/{userId}"
"content_available":true,
"priority":"high"
"notification" : {
"title": "",
"body":""
},
"data" : {
//custom key value pairs
}
}
I have an iOS app that needs to update its content while running in foreground automatically. My app does NOT need to update if in background.
There is a existing way to do so, which is APNS(Apple Push Notification Service).
Because I don't want users to see notification message while in background, using push notification without alert or message might be a solution.
However, if using APNS, iOS would ask users to confirm if they want to receive notifications by my app. I think that users may be confused when being asked by the OS since my app does not actually push notification to users.
The current method I use is keep pulling my API every 30 seconds to see if new content is available. This method would fail if there are too many users.
Is there any 3rd party push-notification-like service that provides notification while app runs in foreground only? (no need to get notification while in background)
You can use Silent notification for that, in this
In the WWDC 2013's "What's New with Multitasking" presentation, there is a section about Silent Push Notifications. if you send the APS payload with just the content-available set to 1, users will not be notified of the notification.
And the notification arrives in application:didReceiveRemoteNotification:fetchCompletionHandler:
Your payload is like
{
aps: {
content-available: 1,
sound: "default"
}
}
In case of push notification, it is necessary for user to accept push notification on application 1st run. You can set a silent push notification also and for this user will not get any alert of getting a notification during application run loop.
If you want to avoid push notification, then you can only set a NSTimer that you are doing already.
There can be a 3rd case, Application only sync with the server when it comes to foreground. And for this you can refer to my this post.