Flutter IOS firebase_message only work in firebase console - ios

i've developed crossplatform app using flutter with firebase_message plugin.
it works well in android system but push notification does not work in IOS partially
when i try to send push notification from firebase console web to all of IOS devices, it works well
but if i try to send using POST method with
<header start>
Authorization : <Firebase server key>
<header end>
{
"collapse_key" : "type_a",
"priority" : "high",
"notification" : {
"body" : "bd",
"title": "tt",
"android_channel_id": "noti_push_NEW_PLAY"
"sound": "NEW_MESSAGE.wav"
},
"data" : {
"click_action": "FLUTTER_NOTIFICATION_CLICK"
"type": "NEW_MESSAGE",
},
"apns": {
"payload": {
"aps": {
"sound": "NEW_MESSAGE.wav",
}
}
},
"to" : <token>,
}
push notificaion does not works in IOS with error NotRegistered
{
"multicast_id": <returned id>,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "NotRegistered"
}
]
}
i don't think it is related with settings, because i can send push message to all IOS devices from firebase web console. but if i try to send it tor specific device, i can't.
i followed all step firebase setup, APN certificate, Apple id, Adding Xcode push notification capablity, etc...
what's the problem???
thanks

I've just resolved it to add
FirebaseAppDelegateProxyEnabled = YES
in info.plist
Not Receiving push notifications from firebase

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

Push Notifications work from FCM console but if sent from API show “InvalidApnsCredential” error (only on iOS devices)

Push notification FMC API doesn't work on iOS
I tried to verify my APNS certificates and seems okay
From FMC console testing notifications work and arrive successfully to iOS devices
Endpoint url
https://fcm.googleapis.com/fcm/send
Request headers:
Content-Type:application/json
Authorization:key=**SERVER_KEY**
Request payload body:
{
"to": "**FMC_DEVICE_TOKEN**",
"priority": "high",
"notification": {
"title": "Title",
"body" : "First Notification",
"text": "Text"
}
}
Response body:
{
"multicast_id": 6714208302733418144,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "InvalidApnsCredential"
}
]
}
This is apparently a global issue from Firebase today. Many people have been reporting this error in the past 3 hours. I hope it's gonna be fixed tomorrow.

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 send push notification from Rest API

I have created my App in Firebase and configured for cloud messaging.
When I am sending the notification from Firebase Console, device gets the notification but if I try to send via Rest API (Using PostMan).
Then notification not coming to device but the response is showing as Success.
Here is my PostMan request
URI - https://fcm.googleapis.com/fcm/send
Header: Content-Type:application/json Authorization:key=MY_SERVER_KEY
Body: { "data": { "title": "Firebase", "detail": "I am firebase" },
"to" : "MY FCM TOKEN HERE" }
Response : {
"multicast_id": 7834540847388366233,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1532422122326299%ebf5f25ef9fd7ecd"
}
] }
I have searched and it seems the way mentioned in documentation is same as I am following
Can anyone let me know why it is not working?
Thanks
I am posting here so as to guide others. As per the guidance of #rv7284, We need to send the data in notification key rather any other key.
So While requesting the body should look like this, Other request parameter like header and all will be same as mentioned in the question.
{ "notification": {
"title": "Firebase",
"detail": "I am firebase"
},
"to" : "YOUR FCM TOKEN"
}

Getting notification in console but not in notification center

Coding iOS app in react-native (0.35.0) and using iPad mini (9.3.5) as a test device. Already made Android app with successfully implementing react-native-fcm module for notifications.
Problem I'm facing now in iOS development is that I do receive notification while app is in background but I do not get it in notif center (I can just catch it in console). I have no idea why is it happening.
This is the module I'm using react-native-fcm . I've followed all the instructions in Cocoapods and in manual integration but I can't make it work. I get no errors what so ever. Tried by directly pushing app to device trough xCode and by archiving it (thought that it might be bundling problem).
Any help would be highly appreciated (even though if someone hasn't worked in react-native but ran into this problem in for example swift). If needed I can provide more information.
Best regards,
Bepo.
EDIT:
I'm sending this JSON:
{
"notification" : {
"body" : "Notif body",
"title" : "notif",
"icon" : "myicon",
"sound" : "default",
"vibrate": "default",
"extra" : "Some extra I need"
},
"data" :{
"redirectUrl" : "Url that I need to redirect person after it clicks on notif"
},
"to" : "token that I've gotten",
"content_available": true,
"priority" : "high",
"show_in_foreground": true
}
with headers:
Content-Type:application/json
Authorization:key= my Api key on firebase
FCM response:
{
"multicast_id": ***************45844,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:********************a1027b"
}
]
}
Notification i'm catching in console:
{ notification:
{ title: 'notif',
sound: 'default',
vibrate: 'default',
icon: 'myicon',
extra: 'Some extra I need',
sound2: 'default',
e: '1',
body: 'Notif body' },
redirectUrl: 'Url that I need to redirect person after it clicks on notif',
collapse_key: 'My app id',
opened_from_tray: 0,
from: '*********' }

Resources