Getting notification in console but not in notification center - ios

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: '*********' }

Related

How can I add 3 custom sounds in react native iOS?

I want to add 3 custom sounds in react native iOS.
Have any of you ever solved it?
Currently, when I test the FCM Notification by adding and grouping a voice file (.wav) to the iOS project folder, one of the added sounds is coming out.
For example, suppose you have sound files sound01, sound02, sound03, when the backend sends an FCM notification, I want the specified sound to sound at that time.
I solved Android but I don't know how to set in iOS environment.
is iOS has channel like android?
I solved it with the code below in the source receiving Firebase Cloud Messaging (FCM).
// remote message processing function
const sendLocalNotificationWithSound = remoteMessage => {
if (Platform.OS === 'ios') {
PushNotificationIOS.addNotificationRequest({
id: remoteMessage.notification.notificationId
? remoteMessage.notification.notificationId
: new Date().toString(),
title: remoteMessage.notification.title,
subtitle: remoteMessage.notification.message
? remoteMessage.notification.message
: '',
body: remoteMessage.notification.body,
sound: remoteMessage.notification.sound
})
} else {
PushNotification.localNotification({
channelId: remoteMessage.notification.android.channelId,
id: remoteMessage.notification.notificationId
? remoteMessage.notification.notificationId
: new Date().toString(),
title: remoteMessage.notification.title,
message: remoteMessage.notification.body,
soundName: remoteMessage.notification.android.sound,
playSound: true,
smallIcon: 'ic_stat_ic_notification',
color: '#FFFFFF',
largeIcon: '',
largeIconUrl: '',
vibrate: true,
groupSummary: true
})
}
}
// remote message receiving
React.useEffect(() => {
const getMessage = messaging().onMessage(remoteMessage => {
sendLocalNotificationWithSound(remoteMessage)
})
return () => getMessage()
}, [])
First, the react-native-push-notification and #react-native-community/push-notification-ios libraries must be installed.
react-native-push-notification
#react-native-community/push-notification-ios
function messaging() in code is #react-native-firebase/messaging library.
you have to import module like:
import messaging from '#react-native-firebase/messaging'
on head in code
The official documentation for react-native FCM (firebase cloud messaging) is here -> REACT NATIVE FIREBASE
FCM sending side JSON sample file
(I test with postman)
{
"to": "your fcm token here",
"notification": {
"title": "your notification title",
"body": "your notification description",
"sound": "your notification sound name (Runs on iOS)",
"android_channel_id": "your android channel id here (Runs on Android)",
"priority": "high",
"contentAvailable": true,
"mutableContent": 1
},
"data": {
... // if you need data property
}
}

Flutter IOS firebase_message only work in firebase console

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

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.

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

Resources