iOS ionic application doesn't receive FCM silent notifications - ios

I have an Ionic 3 application which uses FCM for chat functionality. To handle FCM messaging I use cordova-plugin-fcm.
In my application I use only silent mode (without "notification" payload).
It works fine on Android. In iOS I received messages only if it sent with both "data" and "notification" payloads. If I try to use silent mode , messages aren't delivered at all.
For iOS I use FCM, not APN.
I send FCM messages as in the example of cordova-plugin-fcm.
{
"data":{
"param1":"value1",
"param2":"value2"
},
"to":"/topics/topicExample",
"priority":"high",
}

This stuff works differently on Android and iOS. You need to define the ios-specific apns.payload.aps object within the notification.
apns: {
payload: {
"aps" : {
"content-available" : 1
},
"acme1" : "bar",
"acme2" : 42
}
}
You also need to allow remote background notifications in your plist. If you're using Xcode (the easiest),
In the Project Navigator, select your project.
In the editor, select your iOS app target.
Select the Capabilities tab.
Enable the Background Modes capability.
Enable the Remote notifications background mode.
Source: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW1

Related

didReceiveRemoteNotification not called on background (Firebase, Postman, iOS)

Problem: `didReceiveRemoteNotification` is not called.
I do get notifications when my app is in background. (real device).
I just want to have didReceiveRemoteNotification called whenever notification arrives in background and no user interaction has been made (no tapping).
(My device is iOS 16.3 and Xcode is 14.1)
What I did
I have a Firebase server and I sent a push notification from Postman.
My header
I added apns-push-type, apns-priority, apns-topic (Apple Background push doc)
My Body
I also tried true and "true" for content-available.
{
"aps" : {
"content-available" : 1
},
"to":"my fcm token",
"notification" : {
"title" : "Alarm",
"body" : "Testing"
}
}
Other settings
I did FirebaseApp.configure(),
Messaging.messaging().delegate = self,
UIApplication.shared.registerForRemoteNotifications(), Messaging.messaging().apnsToken = deviceToken.
I also added Push Notifications and Background Modes (Remote notifications, Background fetch)
Assuming you are using the
application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
Did you try changing the content-available to true or "true" instead of using 1?
Refer:didReceiveRemoteNotification not called Swift

Parsing data messages with Firebase Cloud Messaging with Flutter and Firebase on an iOS device

I'm not sure how to go about receiving data messages with FCM and Flutter on iOS.
To give you a quick idea of where I stand, I'm able to receive push notifications on my iOS device. So I've configured everything properly (or so I believe).
So, when the app is in the background, I get a notification in the notifications tray.
When the app is in the foreground, I also receive the message in the onMessage callback.
However, when I try to simulate a data message through an HTTP request to https://fcm.googleapis.com/fcm/send and sending the body :
{
"to" : MY_FIREBASE_TOKEN,
"collapse_key" : "type_a",
"data" : {
"firstKey" : "firstValue",
"secondKey": "secondValue"
}
}
It simply doesn't show up on my onMessage.
I have enabled Push Notifications on my Xcode Project Capabilities.
I have also enabled Remote Notifications in Background Modes in the same Xcode Project Capabilities tab.
I'm not sure what part I've missed because I simply cannot receive a data message.
I have also tried to simulate sending a data message to the sample project in the dart plugin page, but to no avail.
From the plugin README for iOS
Message is stored by FCM and delivered to app via onMessage when the app is brought back to foreground.
If it don't work you should submit an issue to the github repo https://github.com/flutter/plugins/tree/master/packages/firebase_messaging

Firebase messaging not working for "data" messages in iOS

I have an app running on iOS 9.3.5. I need to be able to send a push notification to my app when it's in the foreground or background. I don't actually need to include any data, I just need to ping the app so it will "phone home". So I don't need/want the user to see any notifications.
Since the company is already using Firebase for their Android app, I've set that up in the iOS app. If I send a message to https://fcm.googleapis.com/fcm/send with the notification key in the payload, it's received on the iPhone. When I try it with the data key instead, I get nothing. In both cases I get a success response from the POST. I've implemented the follow callbacks:
application:didReceiveRemoteNotification:
userNotificationCenter:willPresentNotification:withCompletionHandler:
applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage
None of those are called when sending a message with the data key.
Edit:
This is the payload I'm using.
{ "data": {
"message": "phonehome",
},
"to" : "xxxxx"
}
After doing some more testing it looks like I get that message when the app is in the foreground but not the background. When I switch to the foreground then application:didReceiveRemoteNotification: gets called.
Edit 2: Added content_available and that did the trick. Thanks!
{ "to" : "xxxx", "content_available" : true }
It's a little bit hard to suggest without a sample payload, However, do try to use the priority parameter as high or content_available to true.

IOS App implementing Google Cloud Messaging receives notifications only when active

I have implemented in my IOS app the new Google Cloud Messaging framework for handle push notifications. After implementation I'm able to receive push notifications only when App is active and in foreground. If App is closed or in background I didn't get the notification alert in my device. In the iOS notifications settings I see my app enabled to receive them.
I was having a similar problem where the app would receive a notification only if the app was running (foreground/background) and wouldn't receive anything if app was killed manually (terminated)
All I had to do to fix that was to add priority & content_available to the notification body when sending it (as #KayAnn pointed out)
Here's how it should look like :
{
"to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
"content_available" : true,
"priority": "high",
"notification" : {
"body" : "Winter is coming!",
"title" : "John Snow"
}
}
Keep in mind that I also have UIBackgroundModes: remote-notification in Info.plist.
Google documentations (in step 4) quotes:
If the GCMExample application is running in the foreground, you can
see the content of the notification printed to the Xcode debug
console; if the GCMExample app is in the background, you will receive
an APNS notification.
So in order to receive messages when the app is in background you have to register APNS as options as below as described here.
_registrationOptions = # {
kGGLInstanceIDRegisterAPNSOption: deviceToken,
kGGLInstanceIDAPNSServerTypeSandboxOption: #YES
};
EDIT:
There are few other things you need to do:
1) While publishing the app move to production certificate
In the JSON Payload:
2) Use "content_available": "true" OR
3) Set the "priority": "high"
EDIT:2
Using content_available and priority high in the same payload conflicts with Apple's recommendation (Apple docs). I have come across this during my testing. In such a scenario the message may be throttled.
Use either / or of these two parameters instead.
A Tip on working use-cases:
- content_available: use when you are sending data only and do not have other notification specific parameters like alert, badge, sound etc. This is because by default a content_available message is a silent push.
- Priority: high: Use it when you are sending a notification which should reach the users immediately, i.e time critical notifications such as game scores.

iOS Remote Notifications not working when "content-available": 1

I can receive Push Notifications in my iOS app without problems, but if I try to send a Silent Notification adding "content-available": 1, I will not receive any notifications no matter the state of my app (even if it is running in the foreground)
I have checked the Remote Notifications checkbox. (or added remote-notification in .plist) and I have implemented application:didReceiveRemoteNotification:fetchCompletionHandler but didReceiveRemoteNotification only is called if I send a normal push notification and the app is running in the foregound
Any idea??
Check out this answer on SO: Silent Push Notification in iOS 7 does not work
Seems like there is a bug that requires another field to be present for the remote notification to be valid.
I have tested on iOS 7.0.6 to send a slient push with the payload:
{"aps":{"content-available":1}}
and worked fine, here is my userInfo object on Xcode:
2014-05-09 11:04:23.737 SilentPushTest[316:60b] PAyload {
aps = {
"content-available" = 1;
};
}
You can test sending push easily with this app:
https://bitbucket.org/jesuslg123/pushmebaby
Just need to add your app certificate with the name apns.cert and compile it.

Resources