iOS Remote Notifications not working when "content-available": 1 - ios

I can receive Push Notifications in my iOS app without problems, but if I try to send a Silent Notification adding "content-available": 1, I will not receive any notifications no matter the state of my app (even if it is running in the foreground)
I have checked the Remote Notifications checkbox. (or added remote-notification in .plist) and I have implemented application:didReceiveRemoteNotification:fetchCompletionHandler but didReceiveRemoteNotification only is called if I send a normal push notification and the app is running in the foregound
Any idea??

Check out this answer on SO: Silent Push Notification in iOS 7 does not work
Seems like there is a bug that requires another field to be present for the remote notification to be valid.

I have tested on iOS 7.0.6 to send a slient push with the payload:
{"aps":{"content-available":1}}
and worked fine, here is my userInfo object on Xcode:
2014-05-09 11:04:23.737 SilentPushTest[316:60b] PAyload {
aps = {
"content-available" = 1;
};
}
You can test sending push easily with this app:
https://bitbucket.org/jesuslg123/pushmebaby
Just need to add your app certificate with the name apns.cert and compile it.

Related

notifications not received from Firebase

A FCM firebase notification push message was received from the remote message function but does not push on my device. I have set the firebase proxy delegate to yes.
Rembember that push notification not showing on Simulator and when the app is running, just hide app and try send a new notification.
You need to make sure certain things.
You are not testing in a simulator. Notifications are not allowed there.
Payload used to be proper. https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html
Permission for notification should be given.

Is there a way to receive notification when app is killed? That is when app is not working in foreground or background in iOS

I am using APNS push with content-type = 1. I receive the payload and fire using local notification.
this works fine in background and foreground mode
but when app is killed I get nothing.
what is the solution? I have seen people saying something about VOIP apps
but mine is not a VOIP app..
Some said to check Pushkin framework?
Any guidance?
Update
with this Json format I received notification when app was in killed state.. I checked on lower version 9.3 iOS.. have to check on iOS 11..
{
"aps": {
"content-available": 1,
"alert": "custom message ",
"badge": 1,
"sound": "solemn.wav"
},
"id": "55",
"data": "your data"
}
I don't think it can be done if your app is not a VOIP app. But, if you want to change the appearance of a push notification, you may want to look at the Notification Service Extension.
You have to include mutable-content flag as 1 in your payload inside aps. You cannot use content-type flag with this notification. Also, you have to show user something or the other after you have received the payload. Also, it is available in iOS 10 and above only.
Even with all these constraints, you can do some amazing things with this extension which were not possible earlier.
You can now show media attachment in the notification.
You can download small content or hit an API.
You can modify earlier sent push notification.
You can create a local notifcation center in your app.

iOS doesn't receive Push notification when the app is being killed

I have found similar questions on Stack Overflow, but none of them have cleared the point.
I am using Firebase Cloud Messaging for sending push notifications in my app. I am storing the messages received in a local database. When my app is active or in the background, my app is able to receive the notifications (delegate methods called properly) but if the app is being forced quit or not in the memory then also the device is receiving the notifications and sat in notification center but the none of the delegate methods called when the app is being launched by an icon. If a user clicks on Message in the notification center, then the app gets launched, but only the message clicked on is being received and not all of them (in the case of multiple notices have been received).
According to Apple - 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.
But even if the user launched the app still not receive the notifications which were received and sat in the notification center.
Here are the points followed by the app:
My app has no VoIP functionality.
Content-available has been set to 1.
Has enabled to receive background remote notifications.
All notifications sent has been received and displayed in the notification center.
{
aps = {
alert = {
body = "Push Notification Test Message";
title = Push Notification;
};
badge = 1;
"content-available" = 1;
sound = default;
};
"gcm.message_id" = "0:1499340350307980%361a2e5b361a2e5b";
m = "Push Notification Test Message";
tag = m;
}
If the app is being forced quit or not in memory then your app will not receive silent notifications(i.e. Content-available set to 1).
Only push notifications are received in above conditions.
If user clicks on Message in notification center, then app gets launched and only that clicked the message will be received in delegate methods.You cannot access all the messages in the notification tray.
There is no way to get push notifications for the application if app is not running. This is restriction . You are only can get and clear local notifications. So the another way of resolving your problem is saving your notification on the backend when you send it. Then after launching app , you can get notifications list from the server , and match it with id . You can send any parameters that you want in notification playload.
Your app should not rely on the delivery of push notifications. Delivery of push notifications is not guaranteed, as you have found.
Even if your app isn't terminated you may not receive all notifications; For example if the device is in airplane mode and multiple notifications are sent, only the last one is delivered when the device comes back online.
Your app should check with the server for new messages when it is launched or when a notification is received in order to "catch up".
You can also consider including a message payload in your silent notifications. This will be displayed to the user if your app is terminated to prompt them to open your app.
You need to handle method for push notification when the application is open from a tap on any notification. As soon as you tap on notification application will awake and lunch it.
In didFinishLaunchingWithOptions, you need to put below condition:
if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:[launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]];
}
It also called below method when notification is tapped:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
}

iOS - Detect Push Notifications when the App is terminated by the user

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
}
}

UA: didReceiveRemoteNotification:fetchCompletionHandler not being called when app is in background AND connected to Xcode

I would like to implement (silent) remote notifications in my app,
note that I've already implemented regular push notifications.
Steps:
Enable background Capabilities in my project (remote notifications)
Add didReceiveRemoteNotification:fetchCompletionHandlerin my AppDelegate
Send push notification with Urban Airship* (`"content-available" = 1;)
*UA 3.03.
It only works when the app is active in the foreground.
Am I doing something wrong??
Thx
I think I have found the problem:
"content-available" = 1 has to be inside aps
e.g.
{"aps":{"alert":"Hi", "content-available":"1"},"device_tokens":["…"]}

Resources