iOS Grouping Firebase Remote Push Notification - ios

We are using Firebase for sending remote push notifications, we are in need to grouping received notification like WhatsApp (Ex: 25 new messages received). I have tried it by adding APNs in JSON, but it's not working. Here is my tried code:
{
"to" : "**FCM TOKEN**",
"priority" : "high",
"notification" :
{
"title" : "You have a new message",
"body" : "Test",
"badge" : 1
},
"apns":
{
"headers":
{
"apns-collapse-id":"***APNs ID***"
}
}
}
I'm receiving notification but not able to grouping it.apns-collapse-id which was taken from developer.apple.com.

Related

Push notifications via Firebase not appearing on iOS with app on background

We are developing an Ionic app for Android and iOS that has Push Notifications. We send these notifications via Firebase Cloud Messaging
On iOS we have this problem (we have accepted Notifications Permission for the app):
When the app is in foreground, we get the notification instantly (we get it inside the app, not with a card).
When the app is closed or in background it seems like we do not get the notification. However wehn we open or resume the app, we get the notification as is it was recieved with the app in foreground. Our hypothesis is that we are getting silent notifications.
(When we send Firebase test notification we get the same behaviour).
We have the next configurations:
Xcode: Capabilities -> Background Modes -> Remote Notifications (shows one check)
Xcode: Capabilities -> Push Notifications (shows two checks)
Apple Developer: Identifiers -> my app -> Push Notifications (with certificates for both dev and prod)
Apple Developer: Keys -> .p8 key with "Apple Push Notifications service (APNs)"
Firebase: my app -> Configuration -> Cloud Messaging (.p8 file uploaded with key and team IDs)
This is one of the several notifications we have tried to send via Firebase POST API, which combines almost everything we have read while researching this problem. (we also send required Firebase HTTP headers)
{
"to": "<firebase_token>",
"notification": {
"body": "NOTIFICATION BODY",
"title": "NOTIFICATION TITLE",
},
"apns": {
"headers": {
"apns-push-type": "alert",
"apns-expiration": 0,
"apns-priority": 5,
"apns-topic": "<my_app>"
},
"payload": {
"alert": {
"title": "NOTIFICATION TITLE",
"body": "NOTIFICATION BODY"
},
"aps": {
"content-available": 1,
"alert": {
"title": "NOTIFICATION TITLE",
"body": "NOTIFICATION BODY"
}
},
"sound": "default",
"content-available": 1
}
},
"data": {
"field": "1",
"type": "CHAR"
}
}
Despite this POST request may be incorrect for bacground notifications, we believe that would not be the problem, as Firebase test notifications also fail to show when on background.
We finally were able to get notifications with app on background and on foreground.
The payload for Firebase is:
{
"to": "<firebase token>",
"notification": {
"title": "TITLE",
"body": "BODY"
},
"data": {
"title": "TITLE",
"body": "BODY",
"extraField1": "extra value 1",
"extraField2": "extra value 2"
},
"apns": {
"headers": {
"apns-topic": "<my-app>",
"apns-push-type": "background",
"apns-priority": 10
}
}
}
It looked like there were an problem with .p12 certificates after updating to iOS 13 that we solved using a .p8 cert. After changing the certificates at Firebase the background notifications started to be recieved, but foreground stopped for the first hours.
I am not sure, But it seems like your payload structure is not proper.
Please refer below sample
{
"to" : "FCM TOKEN",
"notification" : {
"body" : "Body of Your Notification",
"title": "Title of Your Notification"
},
"data" : {
"body" : "Body of Your Notification in Data",
"title": "Title of Your Notification in Title",
"key_1" : "Value for key_1",
"key_2" : "Value for key_2"
}
}
If you're working with normal APNS then no need to pass content-available
Look for the message in XCode logs. Here is what I got, see below:
In the js code to access body, use data.aps.alert.body
this.fcm.onNotification().subscribe(data => {
console.log("notifiation data", data);
alert(data.aps.alert.body);
Message ID 1: 1593974546767029
{
aps = {
alert = {
body = "Hi, this is ios and android test 6!!!";
title = " iOS and Android Test";
};
badge = 1;
sound = default;
};
"gcm.message_id" = 1593974546767029;
"gcm.n.e" = 1;
"gcm.notification.sound2" = default;
"google.c.a.c_id" = 2904766990309581961;
"google.c.a.e" = 1;
"google.c.a.ts" = 1593974546;
"google.c.a.udt" = 0;
"google.c.sender.id" = 291488852090;
}

Custom push notifications not receiving using firebase

I have implemented an app with custom notification using firebase. I am able to receive custom notifications using device token from the pusher, pushtry, But if I send the same payload using FCM ID from postman then not receiving the notification.
I have tried other payloads also but just receiving the default notification and sometimes only sound for some payloads, but not getting custom one.
I am using the payloads like this for pusher and pushtry:
(received proper notifications)
{
"aps":{
"alert":"dasdas",
"badge":1,
"sound":"default",
"category":"CustomSamplePush",
"mutable-content":"1"
},
"urlImageString":"https://res.cloudinary.com/demo/image/upload/sample.jpg"
}
the same payload not working for firebase
Is there any proper payload for that and is there any need to do changes from my ios code?
thanks in advance.
For custom notification using firebase the payload should be like this.
{
"to": "FCM ID",
"content_available":true,
"mutable_content": true,
"data": {
"message": "Offer!",
"urlImageString":"https://res.cloudinary.com/demo/image/upload/sample.jpg",
},
"notification": {
"body": "Update Your App New Version is available",
"sound": "default",
"click_action": "Your app category from notification plist"
}
}
Your payload should be like:
{
"to": "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
"notification": {
"body": "dasdas",
"title": "Portugal vs. Denmark",
"icon": "myicon"
},
"data": {
"Nick": "Mario",
"Room": "PortugalVSDenmark"
}
}
Having all data under aps does not trigger any notification in iOS even though Firebase returns a successful request because the forwarded APNS payload is not correct. Besides the proper way should be to follow the GCM or FCM payload recommendations, which is to use both notification for the notification message and data for custom key/value pairs.
When FCM Send data to APNS it convert it into APNs payload. It set values of notification in aps tag i.e.
{
"aps" : {
"alert" : {
"title" : "Portugal vs. Denmark",
"body" : "Portugal vs. Denmark",
}
},
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
}

How to handle loc-key in remote Push Notification payload

I've implemented handling of remote push notifications in didReceiveRemoteNotification method in AppDelegate.swift and it works except for payloads of following format.
{
"aps" : {
"alert" : {
"loc-key" : "GAME_PLAY_REQUEST_FORMAT",
"loc-args" : [ "Jenna", "This is Message"]
},
"sound" : "chime.aiff"
},
"acme" : "foo"
}
I want to format and show the content of loc-args on the notification alert. I want to extract "Jenna" and "This is Message" from loc-args and display on alert as below in body and title of alert:
New Message from Jenna
This is message
I've been reading tuts but I can't figure out what exactly I've to do to get it done. I want to keep it simple. Any help?
Tx
Solution was Localizable.strings

FCM Push notification

I am working on FCM, but only below method is getting called.
- (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage {
// Print full message
NSLog(#"This is the message whole structure%#", remoteMessage.appData);
NSLocalizedString(#"This is remote message%#", remoteMessage);
NSString * msg = [remoteMessage.appData objectForKey:#"message"];
NSLog(#"msg %#",msg);
[self alertStatus:msg:#"Alert"];
}
And I got full message from server from this above method only. But none of the push notification methods are getting called.I am not receiving any push notification, so I am unable to receive notification in background.
Ask your backend server developer to add notification key in your payload like this
{
"to" : " ...",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
},
"data" : {
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
}
}
If you want to show notifications for user you should use notification key in your payload.
Reference 1
Reference 2

How to hide push notification in ios?

How to hide push notification in ios? I need to convert push notification to local notification. what should be the structure of payload for this?
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
You can refer the above link to Know about the payload of push notification.
For not showing push notification you need to pass the payload without alert. If you want a silent notification set Content-available as 1. It'll help.
Eg:
{"aps" : {
"content-available" : 1
},
"YourData":""
}
structure of payload for hide the push notification is..
This Show notification
{
"aps" : {
"alert" : "Message received from Bob"
"badge" : 5,
},
"acme1" : "bar",
"acme2" : [ "bang", "whiz" ]
}
This one hide your notification
{
"aps" : {
"badge" : 5,
},
"acme1" : "bar",
"acme2" : [ "bang", "whiz" ]
}

Resources