Firebase messaging data comes to Android but not IOS - ios

In my Flutter app, when I send push notification with Postman, the data is coming to my Android test device,
{notification: {title: MugSafe Powerbank Sizi Bekliyor, body: Hemen alışverişe başlayın},
data: {priority: high, data1: helloworld, click_action: FLUTTER_NOTIFICATION_CLICK,
content_available: true}}
but it is not coming to Ios simulator or real device even logcat.
It works as necessary in Android but not Ios
Should I do something in Xcode for this issue?
My post;
{
"to":"devicetoken",
"notification": {
"body": "Hemen alışverişe başlayın",
"title": "MugSafe Powerbank Sizi Bekliyor",
"sound":"default",
"sound2":"default",
"click_action": "FLUTTER_NOTIFICATION_CLICK"
},
"data": {
"data1":"helloworld"
},
"content_available": true,
"priority": "high"
}

Here is a link where the setup for Cloud Messaging for iOS is explained (https://firebase.flutter.dev/docs/messaging/apple-integration). After you did everything mentioned there, it should work as expected!
Attention: Apple does not support notifications on their simulators!

Related

GCM HTTP protocol parameters & Azure NotificationHub

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

Testing ios push notifications with Xcode 11.4 - link in apns is not working

I'm trying to test push notifications in ios simulator with a new Xcode 11.4 feature.
My app has both NotificationService and NotificationContent extensions to change the message before showing it to the user.
To send a notification to the simulator I'm using terminal command:
xcrun simctl push <simulator_id> <app_bundle_id> push.apns
My push.apns is like this:
{
"Simulator Target Bundle": "app_bundle_id",
"aps":{
"category": "NewOrder",
"alert": {
"loc-key": "NOTIFICATION_KEY",
"loc-args": ["3"]
},
"badge": 1,
"sound": "default",
"types": ["order.created"],
"storeId": "4616",
"mutable-content": 1,
"link": "my-app://orders/3",
"thread-id": "OrderThreadId"
}
}
I see the notification on the screen, but it seems that the "link" attribute is not working. When I tab on a push, I expect to see, in this case, the screen of the third order, but I see the main screen of the app.
I'll be appreciated for any help with this. Thanks.

React native Firebase iOS Production not working by sending noti to FCM single device

I'm doing a React native project with notification, using APNs Authentication Key
. It works perfectly fine on android and iOS dev.
But when I export ipa as adHoc run on device, the app stop receiving notification when I send noti to a single device using FCM. It only works if I send to all iOS devices.
Try to send notification via postman for sent specific user. I think this issue will be the wrong user_key.
POST: https://fcm.googleapis.com/fcm/send
headers:
Authorization:Key='YOUR_SERVER_KEY'
Content-Type: application/json
BODY: raw Data
{
"to": "User_key",
"priority": "high",
"data": {
"title": "Hello world",
"body": "Hello...",
"image": "https://vortex.accuweather.com/adc2010/images/icons-numbered/01-l.png",
"media_type": "image",
"message": "message message message messagemessage message",
"attachment": "https://vortex.accuweather.com/adc2010/images/icons-numbered/01-l.png"
},
"notification": {
"android_channel_id": "news",
"sound": "default",
"title": "Hello world",
"body": "Hello...",
"image": "https://vortex.accuweather.com/adc2010/images/icons-numbered/01-l.png"
}
}

Notification Service Extension does not handle data messages when using Firebase Data Message

The app is on both iOS and Android, for this notification to work on both platforms, I removed notification field from notification json payload. But now iOS does not handle this notification when in background.
This one works on iOS but it has notification field which I do not want.
{
"registration_ids": [
"...",
"..."
],
"priority": "high",
"notification": {
"body": "Notification Body.",
"title": "Notification Title"
},
"data": {
"userId": "11111",
"badge": 10
}
}
This one works in android but not working on iOS when in background:
{
"registration_ids": [
"...",
"..."
],
"mutable_content": true,
"content_available": true,
"data": {
"click_action": "AndroidIntent"
"message": "Notification Body",
"myDataField": "11",
"location": "3",
"imageurl": "http://image.com/13fd.png"
}
}
The bottom one does not even enter my Notification Service Extension. How do I make sure my Notification Service Extension is called without adding a notification field on my json?
I have the same thoughts. I was thinking of receiving data from firebase and push local notification with customized title and body with notification service extention. This idea worked fine in foreground by implementing didReceiveRemoteNotification userInfo: in appDelegate to receive userInfo.
But it didn't work in background mode by enabling content_available. you send notification using APN Servers not Fcm Servers relating to firebase docs. I suggest to have a look in content_available and mutable_content
Remove content_available since this is the property to handle silent notifications.

iOS Push notifications using cordova. The notification is never received

I created a sample Cordova app which is using "phonegap-push-plugin".
That app doesn't have any complexity. On "deviceready" I run the plugin initialization code as shown here:
var push = PushNotification.init({android: {}, ios: {
sound: true,
alert: true,
badge: true,
categories: {
invite: {
yes: {
callback: 'accept',
title: 'Accept',
foreground: true,
destructive: false
},
no: {
callback: 'reject',
title: 'Reject',
foreground: true,
destructive: false
},
maybe: {
callback: 'maybe',
title: 'Maybe',
foreground: true,
destructive: false
}
},
delete: {
yes: {
callback: 'doDelete',
title: 'Delete',
foreground: true,
destructive: true
},
no: {
callback: 'cancel',
title: 'Cancel',
foreground: true,
destructive: false
}
}
}
}})
push.on('notification', data => {
console.log(data.message);
console.log(data.title);
console.log(data.count);
console.log(data.sound);
console.log(data.image);
console.log(data.additionalData);
})
push.on('emailGuests', data => {
console.log('I should email my guests');
});
push.on('snooze', data => {
console.log('Remind me later');
});
push.on('registration', data => {
console.log(data.registrationId);
console.log(data.registrationType);
});
push.subscribe('xx', console.log)
And this is the log output to console:
=> Successfully subscribe to topic xx
// The first run (after app install) will ask for permissions. If I click allow the lines below are printed to console.
=> dCAtjhCFBcU:APA91bG90c8VhNl_BzZ-2e9fmq_9fN6jfrRNJ1LPCRIpKnZ-AG-eLY4xtX84oJRZBh2D....KtNNQ35GM8ubPF5zr8HqeB6jffs
=> FCM
In order to push I'm sending the following payload to the Legacy Server https://fcm.googleapis.com/fcm/send.
{
"priority": "high",
"to": "/topics/xx", // I tried this but I also tried to specify the device token received upon "registration" event. I did this using to:<device_token> and also using registration_ids: [<device_token>].
"notification": {
"title": "My Message",
"body": "My Message Body",
"badge": 1,
"content-available": "1", // I tried with and without
"category": "identifier", // I tried with and without
"thread-id": "id", // I tried with and without
"sound": "default",
"icon": "default"
},
"data": {
"title": "A short string describing the purpose of the notification",
"body": "The text of the alert message",
"clubId": 1000
},
"notId": 1,
"custom_key1": "value1",
"custom_key2": "value2"
}
Note: I tried every combination possible in what concerns the app state: App in background; app closed; app in foreground; The event "notification" has never fired and the push notification was never received.
The request sent to the FCM server returns a message id when I use the topic (which is understandable since other devices subscribe the topic). For that reason my android that has subscribed to the same topic receives the message. The iOS in the other hand receives nothing!
{
"message_id": 5059997308576486332
}
If I try to specify the token that I received upon registration, I will get a slightly different message. Most of the time the token received upon registration works and the results will contain a string id. But this is temporary since a few minutes later the token become "NotRegistered".
{
"multicast_id": 88880398234xxxxx7,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "NotRegistered" // <-- This happens after a few minutes. I have to delete the app and reinstall it in order to get a new token.
}
]
}
This is the build configuration
Notifications are correctly enabled on my iOS device. What am I missing?
Updated:
Accessing Apple's APN directly (yup... no FCM!)
I would like to send my push notifications through FCM but in order to determine the cause of the issues described above, I decided to try APN directly. To do this, I had to remove the from the app's config.xml, so phonegap-push-plugin can obtain a token from APN and not from FCM.
Now, using the new token and a server that uses node-apn module to communicate with APN server, I'm able to send push notifications to my iOS app. The downside of this, is that I lose the ability to push to topics since this is a FCM only feature.
The only thing that I still don't know is how to use the topic to target devices in the APN network, that are subscribed by the push.subscribe() method.
Checkout my issue here.
Any help on this too?
So, turns out there's an issue with the push plugin.
This issue only impacts users on iOS device apps that use the FCM.
If you use the APNs it works.
You can check my answer in here: https://github.com/phonegap/phonegap-plugin-push/issues/2644#issuecomment-445346335
And my initial issue reporting in here:
https://github.com/phonegap/phonegap-plugin-push/issues/2613

Resources