didReceiveRemoteNotification not called on background (Firebase, Postman, iOS) - 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

Related

iOS ionic application doesn't receive FCM silent notifications

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

FCM Push Notification Not Triggering When my App is in Foreground: iOS - Objective C

I have integrated the Firebase Push Notification..
I received the push notification from my server when my app is in
background and when i tap on that didReceiveRemoteNotification methods
gets called, But when my app is in foreground(i.e. active) then
didReceiveRemoteNotification method is not triggering..
My notification payload from server:
"data":{
"message":"mymsg",
},
"notification":{
"title":"mytitle",
"body":"mybody",
"sound": default,
"priority": high
},
"to":"token"
}
Do I need to add any extra key in notification payload or should I do somenthing in my project target?

How can I get array of arrived Remote Notifications in iOS when the application open?

I'm currently developing an iOS application that receive push notification from the web server.
I can receive my notification just fine when the application run in the background / foreground, but when the device is receiving notification while my application got terminated (swiped from the multitasking mode or lock the device), the DidReceiveRemoteNotification method doesn't get called (but the notification & banner does appear!).
So I'm thinking about getting all the arrived (unread) notification and clear all of them when the user launch the application (at FinishedLauncing method) and then I can display some of the message first, because fetching the data from the server do takes some time.
I do can get one message from the launchOptions if the user clicked on one of the notification to open my apps. But is there a way to get them all?
This is not possible to get all the notifications you received.
You can only receive payload of notification on which user tapped or selected from the notification center.
But there is a way, using that you can process your every push notification.
add key content-available with value 1 in to your aps dictionary.
so it will look like,
{
"aps" : {
"alert" : {
"title" : "Game Request",
"body" : "Bob wants to play poker",
},
"badge" : 5
"content-available" : 1
}
}
If iOS system detects pushNotification with this key having value 1,
it will call application:didReceiveRemoteNotification:fetchCompletionHandler: of your appDelegate.
userInfo is the dictionary containing push notifications. aps is the key for push notifications body.
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(#"userInfo %#",userInfo);
// you can get the required message as below
NSString *msg = [userInfo valueForKey:#"aps"];
NSLog(#"Push Notification:%#",msg);
}

How to Know whether Push Notification Delivered or not to an iOS app using Pushsharp?

I'm able to Send Push Notification to an iOS app using PushSharp. But I'm not able to receive delivery Status of that Notification to the recipient. How to know the Delivery Status of Push Notification like whatsapp.
APNS will not provide any Feedback for Push Notification. So we need to use a Silent Push Notification by make use of content-available property in aps dictionary. As we require a Normal Notification, we must put alert, sound, or badge payload in the aps dictionary. So that The Push Notification will visible to the User. As we are using content-available property in payload, iOS wakes up our app in the background so that we can send Delivery Report to our Web Server.
Sample Payload:
{
"aps" : {
"alert" : "Sample Push Notification.",
"badge" : 2,
"sound" : "sound.aiff"
"content-available" : "1"
}
}

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