Since Xcode 11, iOS simulators can now receive push notifications. This can be accomplished by executing a specific command or providing a JSON file to the simulator. I got this information from this blog: Test Notification on Simulator.
However, in my use case, I use Firebase Cloud Messaging to deliver notifications to the user of my app (Android and iOS both). I am unable to test the notification generated by Firebase on a simulator as the payload is different for FCM.
Is there a way to achieve this?
I found a similar question on the topic but there's no answer on it so far.
For Testing push notifiction in simulator just creat a new file and paste following json object and save file in .apns , and then just drag and drop this file in simulator then push will work.
{
"aps" : {
"alert" : {
"title" : "sarunw.com",
"body" : "A asdfsadfsadf"
},
"badge" : 5
},
"Simulator Target Bundle": "bundleId"
}
For differenct payload just use following JSON object in Postman
{
"to" : "ewebWDSSwYc:APA91bGOARO4eq9LlOfgfXPQZMK3IiRFanhzSSgkD6cVqJiPbnyuEgsvQMarDEl6Hg7_UMtFM6Hn90jyTsSENNqLNNLVjLSypR0voAO3j6orIsgabX-t0cpfJ0qpB2SzhZiXvor0r__d",
"notification":
{
"title":"ABC",
"body":"123",
"mutable_content" : true,
"category":"CustomSamplePush"
},
"data":
{
"sender_contact_code" : "+92",
"sender_contact" : "(555) 564-8583",
"group_name":"Testing Group",
"type":"NewMessage",
"type_id":"1213",
"notification_type_id":"123213"
}
}
with this url -> https://fcm.googleapis.com/fcm/send
(Type will be POST)and in authorization you need to put Server key in Key Value, in that way you will be able to send push notification with your own formatted object.
also you can use Pusher for testing push notifiction & I have uploaded screenshot for reference.
Since Xcode 12 (not 11), it's possible to registrer to push and receive via the APNS payload. If the drag & drop it not working, you can use Terminal :
xcrun simctl push booted YOUR_BUNDLE payload.json
With :
"booted" = the current simulator
"payload.json" = the APNS file on
your Mac.
It may look like:
{
"Simulator Target Bundle": "xxx.xxx.xx ",
"aps":{
"alert":{
"title":"XXX",
"body":"YYY YYYY"
},
"badge" : 5,
"data":{
// stuff
},
"mutable-content":1
}
}
maybe you found the solution a long time ago but here is how i made it work:
to allow FCM notification to be catch in your app you need to add that in your .apns file
"gcm.message_id":"20021"
here is the apns file i use to test FCM notifs on my Iphone simulator:
{
"Simulator Target Bundle": "XXX.XXXXXX.XXX",
"aps": {
"alert" : {
"title" : "Test notif",
"body" : "Should update widget && refresh feed"
},
},
"gcm.message_id":"20021",
"data": {}
}
Related
We already have GCM/FCM setup up and we are able to send notifications to both iOS and Android devices.
More specifically data-only notifications where we add the parameters ( priority, content_available, collapse_key )
Especially the content_available parameter is crucial when the phone is an iOS device and in order to receive the data-only notifications when the app is in the background. But behaviour seems to be different between https://fcm.googleapis.com/fcm/send call and Portal -> Azure Notification Hub -> Test Send ( or SendFcmNativeNotificationAsync )
Working Case
Everything works as expected when I use the https://fcm.googleapis.com/fcm/send call.
So we have the following message for example:
{
"to": "…REDACTED_THE_ID...",
"collapse_key" : "123456769",
"priority": "high",
"content_available":true,
"time_to_live": 600,
"data": {
"content": {
"id": "9d2b0228-4d0d-4c23-8b49-01a698857710"
},
"dataType": "terminal"
}
}
Issue To Reproduce
But when we use the following message in the Portal -> Azure Notification Hub -> Test Send
Platforms "Android" ( which uses the same Google GCM API Key )
Remove the “to” entry as I am using the "Send To Tag" expression
Azure Notifications hub approves the message and confirms that message was successfully sent.
But then nothing arrives on the iOS smartphone, it seems as if the content_available parameter is not taken into account.
If I add a valid “notification” field (which makes it a NON- data-only notifications ) then it arrives.
{
"collapse_key" : "123456769",
"priority": "high",
"content_available":true,
"time_to_live": 600,
"data": {
"content": {
"id": "9d2b0228-4d0d-4c23-8b49-01a698857710"
},
"dataType": "terminal"
}
}
I am trying to implement cache meachanism for FCM on IOS. I am using Xamarin Forms with CrossGeeks FirebasePushNotificationPlugin
Push notification service works fine. I am using payload pattern as below
{
"data": {
"message" : "my_custom_value",
"other_key" : true,
"body":"test"
},
"notification": {
"body" : "hello",
"title": "firebase",
"sound": "default",
"content_available" : true
},
"priority": "high",
"condition": "'general' in topics"
}
Above pattern appears delivered notification as alert on IOS main screen.
I have written a Dependency Service for getting undeleted or unopened accumulated notifications when app starts. Dependency Service include below codes
await UNUserNotificationCenter.Current.GetDeliveredNotificationsAsync();
When I use above payload, I can get accumulated notifications. But when I use payload pattern as below, I can not.
{
"data": {
"message" : "my_custom_value",
"other_key" : true,
"body":"test"
},
"notification": {
"content_available" : true
},
"priority": "high",
"condition": "'general' in topics"
}
Actually I would like to send 2 payload types for every notification for my cache mechanism because of prevent the user's delete action. After that, I would like to show cached notifications without any lost in my app's notification page.
Shortly my question about "I am not getting silent payload values from UNUserNotificationCenter this approach is possible or not?"
Or can I prevent the user's notification delete action from IOS main screen when my app is terminated.
Note: My minimum OS version is 10.0 in info.plist
Thank you in advance.
I am using firebase notification in my application. I want to send rich notification but firebase console don't have UI for same. So I am trying to send the payload using postman.
I have created Notification Service Extension for handling content but it never gets called.
Deployment target in xCode is iOS 10.0 and iPad has iOS 11
Json payload(Not Working):
{
"to":"/topics/dev_news",
"mutable_content": true,
"data":
{
"attachment-url":"my image url",
"media_type":"image"
}
}
FYI:
I am able to receive push if I add "notification" key-value in payload.
Json payload(Working but without media):
{
"to":"/topics/dev_news",
"mutable_content": true,
"data":
{
"attachment-url":"my image url",
"media_type":"image"
},
"notification" : {
"title" : "demo push",
"body" : "this is push body"
}
}
Any idea about this??
Answering to my own question, I was searching for attachment-url in data dictionary (which I was passing in the payload) in service extension class. But attachment-url comes directly in the content.userInfo (It is not wrapped inside the data dictionary) in extension class.
Wondering how I can make such a silly mistake..!! :D
Im using the new Firebase platform. Am trying to get a push notification sent by my app server and delivered to my iPhone.
I have the setup working where I manually send the message with the Firebase notifications area on the website, but when I try and send the message with a POST to https://fcm.googleapis.com/fcm/send I get no message being delivered to the device.
I'm sending the following (with auth headers)
{ "notification": {
"title": "Portugal vs. Denmark",
"text": "5 to 1"
},
"to" : "<registration token>"
}
I'm getting a 200 response from the POST with the following body:
{
"multicast_id": 5511974093763495964,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1463685441784359%3ad254b53ad254b5"
}
]
}
If I try and send to this device directly through the Firebase website it works, but the above form post doesn't. No idea where to go from here!
On iOS the priority field seems mandatory.
{
"to": "cHPpZ_s14EA:APA91bG56znW...",
"priority": "high",
"notification" : {
"body" : "hello!",
"title": "afruz",
"sound": "default"
}
}
If the API returns you a message_id it means that your message has been correctly accepted and it will eventually be delivered to the device.
On Android, messages are delivered as soon as possible (provided that the device is connected of course).
On Apple devices, IF the application is closed or in background, the notification is sent through Apple infrastructure and can be delayed accordingly with Apple documentation.
To reduce the delay of the prioritymessages sent to Apple device you can use the priority parameter.
More details: https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message
I found the message field to be required, as well as the priority field to deliver a message with a POST.
message is not required (and labeled as optional) in the Firebase Console.
I resolved adding the notification tag in request body without priority.
Here is a recap:
i'm a beginner iOS developer (so.. sorry if I made a stupid mistake).
I have succeeded implementing GCM, it's running fine when plugged in (run with XCode). But when I unplug my device from my PC, it stopped prompting the banners.
So, when :
plugged in -> While opening application -> JSON Recieved
plugged in -> While application on background -> Banners Appear
unplugged -> While opening application -> JSON Recieved
unplugged -> While application on background -> Nothing
I use these JSON
{
"content_available":true,
"to" : "l6rofh8dvAc:AP......BVhhXSYc3thtGklEzJzoZFGRMI7lBk4RhmcW",
"message_id": "1",
"notification" :
{
"body" : "helloo!!",
"title" : "GCM",
"icon" : "",
"sound": "default",
"alert":"default",
"badge":"12",
"color": "#03A9F4",
},
"data":
{
"body":"Hello, How are you?",
"title":"Test"
}
}
is my JSON wrong? or is there something that I missed at the XCode? (i followed the sample from
Setting up a GCM Client App on iOS - Sample (with little modification).
You should set the priority of the message as high. The way you're setting it the priority is set to be low and APNS optimizes battery while sending the message and usually takes hours to deliver the message.
Here is what you need your json to be
{
"content_available":true,
"to" : "l6rofh8dvAc:AP......BVhhXSYc3thtGklEzJzoZFGRMI7lBk4RhmcW",
"message_id": "1",
"priority" : "high", # Add this
"notification" :
{
...
},
}
You can read more about setting priority here https://developers.google.com/cloud-messaging/concept-options#setting-the-priority-of-a-message