JSON structure for an iOS 9-10 silent push notification - ios

We are developing an app which could receive remote push notifications. We just understand that there are two types of notifications, “normal” and silent.
We want to know the JSON structure of a silent notification with message.
{
"notification_type":2,
"aps":
{
"alert":"Message de la notification",
"content-available":1,
"badge":1,
"sound":"default"
}
}

For silent push notifications we omit the alert, badge and sound (that are not used in silent pushes) keys and then the notification is not displayed, but the handler is called. The json should look like this:
{
"aps":
{
"content-available":1,
}
}
You can send extra contents with the notification too, so your app will know what to do:
{
"aps":
{
"content-available":1,
}
"example-action": "example"
}

Related

Notification delegate not being called when app is in background when notification is received

I am using firebase cloud messaging to send push notifications to our iOS application. When the application is in the foreground everything works fine.
The problem is when i send the app to the background and then send a notification.
I expect the following delegate to be called, but it is not:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult)-> Void) {
I have ticked the "remote notifications" background mode in my apps signing & capabilities tab.
The payload i send to firebase looks like this:
{"to":"--TOKEN--",
"priority":"high",
"content_available":true,
"mutable_content": true,
"notification":
{"body":"Test Notification",
"title":"New Notification",
"sound":"default",
"click_action":"notification"
}
}
This payload is sent to firebase via https://fcm.googleapis.com/fcm/send
When i click an notification it is then processed, and i can see the apns version i receive looks like this:
[AnyHashable("google.c.sender.id"): 8xxxxxxxx, AnyHashable("gcm.message_id"): 1xxxxxxxxxx, AnyHashable("google.c.a.e"): 1, AnyHashable("google.c.fid"): fxxxxxxxxx, AnyHashable("aps"): {
alert = {
body = "Test Notification";
title = "New Notification";
};
category = feedback;
"content-available" = 1;
"mutable-content" = 1;
sound = default;
}]
I am not sure why content-available and mutable-content appear in quotes? I know firebase convers its payload to apns format, is there something wrong here?
I want the delegate to be called so that i can execute some code to maintain various data items, so it is important that i can run some code when my app is in the background and a notification is received.
I am not sure what config i am missing as everything i read seems to say this is all i need to do?

FCM silent push notification structure for iOS?

I need example of notification payload for silent notification, I tried this below structure, but it's not working
{
"notification" : {
"body" : " Survey list updated",
"content-available:" : true,
"data" : {
"isNewUpdateAvailable" : "easysurvey.survey_list_updated"
}
},
"to" : "f6PwToRUxk0:APA91bG7bSWoKsjHXVmXaiDEnFXA2x2jEOMSO6eGCqPv1fRd-dctNLDEabRq-0So_obuPGFqOFTSLJl5FFyuOuXKBXh-n89BmzzXenRTxoirY9Y1c6-J9MxpDp0ojHL2xm1law0V6gg3"
}
Using this structure, I am able to receive notifications, but it's not silent & doesn't wake the app.
i need solution for firebase notification & on iOS 10,
i am following same firebase sample code
i got the answer, write payload structure in this way.
{
"data":{
"title":"mytitle",
"body":"mybody",
"url":"myurl"
},
"notification":{
"title":"mytitle",
"body":"mybody",
"content_available": true
},
"to":"DEVICE_FCM_TOKEN"
}
this may help someone.
if you wish to test FCM notification using POSTMAN Api client, use "key=YOUR_SERVER_KEY"

Gcm ios push notifications in background fail

I can receive push notifications when my app is in foreground but it is not working in background.
When I send the json has this form:
{
"data":{"message":"test ios push notification"},
"time_to_live":604800,
"registration_ids":["key...."],
"collapse_key":"GCM Notifications",
"content_available":1,
"priority":"high"
}
In my application I get in foreground (nothing in background):
{
aps = {
"content-available" = 1;
};
"gcm.message_id" = " whatever ";
message = "test ios push notification";
}
I think that the problem is around content_available but I dont know why I send content_available and the return is content-available. Is this a normal conversion?
SOLVED!
Me bad, I forget to enable it in target -> Capabilities section:

Push notification sound is not working

I am using Push Notifications in my app.when notifications comes,i am not getting the notification sound of the notification and also in iPad settings i switched-on all the notification buttons in iPad even though the notification sound is not coming.
{
alert = "Testing commands#2014-12-01T12:16:26",
sound = "default"
}
I am getting the sound file like this.But the notification sound is not coming.
I am new to the PushNotification concept.Can anyone please help to solve this...
you should use JSON format to send your notifications encapsulated in aps dictionary like:
{
"aps" : {
"alert" : "Your message.",
"badge" : 0,
"sound" : "default"
}
}
for complete reference:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

How we can fetch push notification in background

I am receiving push notification in that payload message i am receiving one URL with message as push notification. but i dont want to show URL to user i want to show only message to user. is it possible from ios side.
If your are using url as a separate key in aps then its possible you can display alert only as a message, otherwise any message can't be modify message in background.
"aps": {
"alert": "alert!",
"sound": "default",
"URL" : "your url"
}
yes, its possible but it also depend on how you have created your payload but its simple as you create your payload with your link and message, receive at your delegate
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)pushChatObject {
// get the message value and NSLog is or set to UIAlert or in NSString
(pushChatObject)[#"Message"];
}
You can, but you shouldn't, because
Delivery of notifications is a “best effort”, not guaranteed. It is
not intended to deliver data to your app, only to notify the user that
there is new data available.
(c) Apple
Specify the notification message as
{
"aps": {
"alert": "alert!",
"sound": "default"
},
"URL": "http://apple.com"
}
When you receive the notification in the app just check for your param in the notification dictionary:
// Place this method to AppDelegate.m
- (void)application:(UIApplication *)application didReceiveRemoteNotification:
(NSDictionary *)notification {
if ([notification objectForKey:#"URL"]) {
NSString *url = [[notification objectForKey:#"URL"] stringValue];
}
}
Check this section of Apple's Local and Push Notification Programming Guide for more info
I think in this case you can use Child properties of the alert property, you use 1 argument as a alert and another argument as a url, like:
"aps": {
"alert" : {
"loc-key" : "ALERT",
"loc-args" : [ "Your alert message", "Your url"]
},
"sound": "default"
}
When the device receives the notification, it uses "ALERT" as a key to look up the associated string value in the Localizable.strings file in the .lproj directory for the current language. Assuming the current localization has an Localizable.strings entry such as this: "ALERT" = "%#";
And later on you can get your url using aps NSDictionary.

Resources