I'm using FCM to publish push notifications to my users, which is working great so far.
Currently I'm trying to implement a Notification Content Extension to deliver customized push notification and previews, which is working great with local notifications, following this post.
As far I know, I have to set the category entry and my notification category identifier in the push notification, in order to tell iOS, which notification UI it is supposed to use.
The problem is, when I send the following message to FCM, with the category entry set, FCM erases the entry or changes it to gcm.notification.category, depending where I place the category entry (aps / data, etc.)
This way iOS never shows my custom UI / extension. Unfortunately I was not able to find any help in the FCM documentation.
Send (POST: https://fcm.googleapis.com/fcm/send):
{
"notification": {
"title": "Good Morning",
"body": "Wake up Jack!",
"badge" : 1,
"sound" : "horn.aiff",
"category" : "Cheers" <-- Is going to be deleted / changed
},
"data" : {
"time" : "2018-01-19 23:00:00",
...
},
"mutable_content" : true,
"priority" : "high",
"registration_ids" : [
"abcdefg123456"
]
}
Received:
{
aps = {
alert = {
body = "Wake up Jack!";
title = "Good Morning";
};
badge = 1;
"mutable-content" = 1;
};
"gcm.message_id" = "0:1516392279506894%dc84760ddc84760d";
"gcm.notification.category" = "Cheers"; <-- not working
}
The category APNS parameter FCM counterpart is click_action.
When adding in a custom parameter (using the data message payload), it is handled differently for iOS and is often included outside of the aps payload (like in the sample you provided).
Related
I'm new to using Apple APN to send push notifications. With FCM (Firebase), there is an 'image' property you can use to send a big picture with your push notification. It doesn't look like there is an option to send a big picture with your push notification using Apple APN based on this documentation:
https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification
This is an example of a post request using the Apple APN:
"aps" : {
"alert" : {
"title" : "Game Request",
"subtitle" : "Five Card Draw",
"body" : "Bob wants to play poker"
},
"category" : "GAME_INVITATION"
},
Is there an property you can use in the aps object or the alert object that allows you to send a big picture with your push notification?
How do you send a big picture with your push notification using Apple APN?
Are you sending your notifications via firebase?
Then actually there should be an option, but you need then to specify the picture for the different platforms like:
const message = {
notification: {
title: 'Sparky says hello!'
},
android: {
notification: {
imageUrl: 'https://foo.bar.pizza-monster.png'
}
},
apns: {
payload: {
aps: {
'mutable-content': 1
}
},
fcm_options: {
image: 'https://foo.bar.pizza-monster.png'
}
},
webpush: {
headers: {
image: 'https://foo.bar.pizza-monster.png'
}
},
topic: topicName,
};
As I understand the documentation and the example here you can only send a link that will be loaded on receiving the picture.
Another idea could be to put the same in a custom payload in a data object within the message. But keep in mind there are some limitations to notifications:
limits for push payload size determined by Google and Apple — 4096 bytes (in iOS 8 and lower, the maximum size allowed for a notification payload is 2048 bytes [1]).
Links to further explore:
[enter link description here][1]
[enter link description here][2]
[1]: https://help.pushwoosh.com/hc/en-us/articles/360000440366-Limit-of-characters-that-can-be-sent-through-a-push-notification#:~:text=Answer%3A,is%202048%20bytes%20%5B1%5D).
[2]: https://firebase.google.com/docs/cloud-messaging/ios/send-image
I use firebase and get successfully Notifications but when notification arrived, do not get call NotificationService.h Notification Service Extension.
I also set
NSExtensionPrincipalClass to NotificationService
NSExtensionPointIdentifier to com.apple.usernotifications.service
My notification is like
{
"registration_ids": ["devicetoken"],
"mutable_content": true,
"data":{
"post_details": {
"pcm_message": "asdf",
"pcm_img_url": "http://portalvhds34w6bf5z9b21h.blob.core.windows.net/images/1519365008_5a8fab90cf683.jpg",
}
},
"notification" : {
"title" : "demo push",
"body" : "this is push body" }
}
where is a problem or missing some information I have already set deployment target 10.0 in my whole project.
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"
I just want to know how I can determine what action to do on a silent push:
This is the aps that I sent to the client:
"aps": {
"content-available": 1
}
My problem now is when I add type: "Order_Update" to determine that the silent push is for the Order Update to display an alert notification.
There are a few options for it! Let's take a small ride to understand all the different payloads and their usage.
Simple Payload
Displayed in Notification Center : Yes
Wakes app to perform background task : No
{
"aps" : {
"alert" : "You received simple notification!",
"badge" : 1,
"sound" : "default"
}
}
Payload With Custom Notification Sound
Displayed in Notification Center : Yes
Wakes app to perform background task : No
Step 1 : Add custom notification sound file (.wav or .aiff extensions only. e.g. notification.wav) in your app bundle.
Step 2 : Configure your payload as shown below to play your custom sound
{
"aps" : {
"alert" : "It's a custom notification sound!",
"badge" : 1,
"sound" : "notification.wav"
}
}
Notification With Custom Payload
Displayed in Notification Center : Yes
Wakes app to perform background task : No
{
"aps" : {
"alert" : "It's a notification with custom payload!",
"badge" : 1,
"content-available" : 0
},
"data" :{
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
}
Here the data dictionary holds custom information whatever you want. It will also display as normal notification with the alert message "It's a notification with custom payload!".
Normal Silent Notification
It will not a show an alert as a notification bar; it will only notify your app that there is some new data available, prompting the app to fetch new content.
Displayed in Notification center : No
Awake app to perform background task : Yes
{
"content-available" : 1
}
Silent Notification With Custom Payload
Here comes the magic to show a notification alert as well awake your app in background for a task! (Note: only if it's running in background and has not been killed explicitly by the user.)
Just add the extra parameter "content-available" : 1 in your payload.
Displayed in Notification Center : Yes
Wakes app to perform background task : Yes
{
"aps" : {
"alert" : "Notification with custom payload!",
"badge" : 1,
"content-available" : 1
},
"data" :{
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
}
}
Use any of these payloads according to your app requirements. For background app refresh refer to Apple's documentation. I hope this gives you all the necessary information. Happy coding :)
As i understand, you want extra data inside payload, so you can identify what push notification type is,or what action need to be handled.
For that edit your payload as:
$body = array(
'content-available' => 1,
'sound' => ''
);
$payload = array();
$payload['aps'] = $body;
$payload['action'] = 'order_update';
Then in your iOS Code:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSString *action = userInfo["action"];
if([userInfo[#"aps"][#"content-available"] intValue]== 1 && [action isEqualToString:#"order_update") //order update notification
{
//handle Your Action here
return;
}
}
Hope this solves your problem!
Please also check apns-push-type (Required for watchOS 6 and later; recommended for macOS, iOS, tvOS, and iPadOS) The value of this header must accurately reflect the contents of your notification’s payload. If there is a mismatch, or if the header is missing on required systems, APNs may return an error, delay the delivery of the notification, or drop it altogether.
https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns
In my application Push notification receives data in json format
Which is this
aps = {
alert = "{\"messsage\":\"what to do when boarded \",\"chatBox\":\"130701.130693\",\"sender_id\":\"130701\",\"sender_name\":\"reg41\",\"sender_image_url\":\"http:\\/\\/www.playmit.com\\/images\\/user_profile_images\\/\",\"receiver_id\":\"130693\",\"type\":\"chat\"}";
};
}
But also on lock screen when app is not running or app is in background when push notification received it shows same json contents in push notification
So how do I handle this.
Thanks.
In the image Quizmatch receives push notification in json format
You are not allowed to put custom tags inside aps tag. Here's what documentations says about it:
Providers can specify custom payload values outside the Apple-reserved aps namespace. Custom values must use the JSON structured and primitive types: dictionary (object), array, string, number, and Boolean.
So in your case you should do something like:
{
"aps": {
"alert": "Hello World",
"sound": "default"
},
"Person": {
"Address": "this is a test address",
"Name": "First Name",
"Number": "023232323233"
}
}
Therefore you can read your custom payload with looking for it's key in main JSON, rather than in "aps":
NSLog(#"%#",notification['Person']['Address']);
Above will output:
this is a test address
You could find more about custom payloads, along with some examples in Apple docs.
Reference:link
if user is not prevented from settings, aps.alert is always displayed
{
"aps": {
"badge": 10,
"alert": "Hello world!",
"sound": "cat.caf"
},
"job_id": 1
}
update your notification structure like this, send data under some other key like "job_id"