I am using Firebase to set up push notifications on iOS 10.
My app is receiving remote messages while in the foreground, but not in the background. Background messages are only received on opening the app.
Somehow all push notifications are received through applicationReceivedRemoteMessage:, Firebase's data message delegate, while in fact I never send a data payload.
I exactly implemented AppDelegate as mentioned in the tutorial on Firebase's website, I set the APNS tokens myself and the certificates are all in the right place. Also, my payload is sent with priority 'high' and content-available.
Anyone got an idea why iOS 10's native remote message handler (userNotificationCenter:willPresentNotification:withCompletionHandler:) is never called instead?
Thanks a lot! (Have been debugging this for two days straight now...)
I just ran into this same problem.
I resolved it by adding the following text to sender:
"notification":{"body":""}}
Don't set the Firebase delegate and just handle it in the old method
didReceiveRemoteNotification
look into firebase method swizzling
The FCM SDK performs method swizzling in two key areas: mapping your
APNs token to the FCM registration token and capturing analytics data
during downstream message callback handling. Developers who prefer not
to use swizzling can disable it by adding the flag
FirebaseAppDelegateProxyEnabled in the app’s Info.plist file and
setting it to NO (boolean value). Relevant areas of the guides provide
code examples, both with and without method swizzling enabled.
Related
This bounty has ended. Answers to this question are eligible for a +500 reputation bounty. Bounty grace period ends in 5 hours.
Scorb wants to draw more attention to this question.
I have a cross platform flutter app. I am using FCM to send notifications and they are not arriving on the iOS app in any state (foreground, background, terminated). I am testing on a physical device.
The notifications work on Android, so I know the topic subscription and send code is correct.
I have followed these steps for configuration defined here...
https://firebase.flutter.dev/docs/messaging/apple-integration/
To verify I have:
added and initialized firebase using google-services-info.plist.
created and added my APNS key
created the app identifier in the Apple Developer center and confirmed it matches my apps bundle id (and added push notification
capability for the identifier.
added push notification capability to the app in xcode
added background fetch and background remote notification capabilities to the app in xcode.
It seems like I have addressed every step to configure FCM on iOS. But none of my notifications arrive.
When the app is minimized, no system tray notification is triggered, and when in the foreground the FirebaseMessaging.onMessage is never triggered, like is is when on Android.
An important note is that this is the second iOS app added to this project, and the first iOS app works correctly. Though there is no indication that there are any special steps for a second app.
We saw a similar problem (for a native iOS app) where FCM would deliver to one app in the project but not the other. The mistake we made was not repeating the configuration in Firebase for the other apple bundle id since each app in our project has a different bundle id. Given it works for one of your iOS apps but not the other on the same project, it sounds like you've got the same issue.
Also, a good diagnostic step is to use the Firebase Console to manually send off a Push Notification to a particular app. It means you can then discount errors further upstream in your backend that may not have caused FCM to be invoked.
Have you tried to send testing notifications via firebase console?
You can log your device token in your app.
Background notification must work if you have done correct with firebase and APN settings despite without implementing some methods of AppDelegate file for remote notification on the next step.
Your question is very blur to have a specific answer but you can separate your concerns to find the issue and then try to resolve that:
1. Make sure about the APNs configuration
First, try to send a notification to your iOS app, directly using the APNS key. If you get the notification, it means you have configured the APNS correctly
2. Make sure about the firebase setup
Check with both the Android and iOS app and see if there are connected to the firebase console. You can use the real-time event to confirm that.
3. Make sure you have implemented the correct methods.
Firebase and apple have different methods for push notifications. Make sure you are implementing the correct one. Also, it may vary based on the configuration file of firebase. search for iOS firebase swizzling for more information
4. Make sure you got the right permissions from the user
You should get the notification permission from the user before trying to show any notification. Make sure you've done that
Note that you may have already tried some of these but I've mentioned them for the sake of completeness. Hope it helps you and others.
Update...before I ever posted
I actually discovered the solution before I posted this but thought I'd post it anyway in hopes of saving someone else's time.
As a last resort I tried deleting the APNs Authentication Key and reverting back to the certificate for the application in Firebase Cloud Messaging project settings. That fixed it. Below is the message I'd intended to post.
I'm attempting to push notifications to subscribers of a specific topic using Firebase FCM. According to the Cloud Messaging console the notifications are being sent but they're never received by a device subscribed to the topic. I'm also not receiving test messages sent via the console.
I've confirmed the following:
APNS is properly configured for my project. I was able to receive a
notification on a device using a testing site
(https://www.apnstester.com/apns/)
The topic is being subscribed to or at least subscribeToTopic doesn't
return an error.
I'm receiving a remote instance ID token.
I'm receiving an APNS device token
I've also tried:
Enabling and disabling swizzling (and yes, when it's disabled I'm
setting the APNS token)
Deleting and reloading my APNs Authentication Key
Updating the Firebase framework
Removing and re-adding the GoogleService-Info.plist
I should point out this is old app (hence the Objective-C swizzling) and notifications worked fine in the past. Any suggestions or advice?
My code is in Objective-C
Firebase side
App created
General settings --> done
APNs Auth Key --> done
Apple developer account side
App ID --> done
Dev and Distribution certificates --> done
Dev and Distribution profiles --> done
App side
My AppDelegate calls registerForRemoteNotifications without any error and the method "didReceiveRegistrationToken" is able to return a string like in the following: NSLog(#"Remote instance ID token: %#", result.token);
First item confirms that my app is able to reach Firebase Server and APNs because a TOKEN returns always!
I have implemented all functions didReceiveRemoteNotification both if I am receiving a notification message while the app is in the background and if it isn't.
GoogleService-Info.plist --> moved inside my project
PROBLEM
The problem is my app is not able to receive any notification I am going to send by using the firebase console. didReceiveRemoteNotification never called!
I have read all your feedback on other questions but I didn't solve my problem.
UPDATE #1
Thank you iDev750 for your answer!
My problem is I do not receive notifications on my app when I send them from the firebase console or directly from my backend. In my opinion if I do not receive a notification it is impossible that didReceiveRemoteNotification is called, are you agree with me?
Anyway, as you said, I sent a push message directly to my token/device and the result is in the following:
{"multicast_id":6185922XXX,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1543141675131005%YYYY"}]}
So, it is sure the message has been sent, otherwise the output should be something like The request's Authentication (Server-) Key contained an invalid or malformed FCM-Token (a.k.a. IID-Token).
I hope I was clear with this my second message. Do you have any idea to help me?
Thank you so much!
Here you said two points in your question.
Notification is not receiving in your app.
didReceiveRemoteNotification never called.
First, which is your problem? becasue both are different issue.
You can do one thing that just install your app in iPhone and paste your device token on Firebase console and send test notification on that device. Just forget about "didReceiveRemoteNotification" method that calling or not.
Now, if you are getting notifications but didReceiveRemoteNotification is not calling then check my answer:
https://stackoverflow.com/a/53460880/1673192
If notification is receiving on the device, might be some other issue like -
Is push notification enable for your AppId created on AppStore?
Is push notification enable in your app -> Targets -> Capabilities -> Push Notifications
Check these points and let me know still you have any issue.
we are trying to implement push notification on Android and iOS app, we are using Firebase Cloud Messaging to send push notification to our app.
actually my iOS app can connect to the Firebase Cloud Messaging, If I send the notification through firebase console notification, I can receive the notification in my app
but if the message is sent through our backend server (PHP), I will not receive the notification in my iOS app, but that message will be arrived in our Android App.
we are still trying to figure out the problem, either it is from client side or from server side. but from the backend server, it send a response error
Invalid (legacy) Server-key delivered or Sender is not authorized to
perform request.
but I also have to ensure that the problem doesn't come from my iOS app. but I also have a doubt, because in my debugging area, it show a message
FIRMessaging Remote Notifications proxy enabled, will swizzle remote
notification receiver handlers. If you'd prefer to manually integrate
Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your
Info.plist, and set it to NO.
in info.plist i set the value of FirebaseAppDelegateProxyEnabled to YES
if I set this to NO as per the message from debugging area like above , then I will not receive the push notification, thats why I set that to YES.
To be honest I completely have no idea what the purpose of that FirebaseAppDelegateProxyEnabled
what is the function FirebaseAppDelegateProxyEnabled ?, is that the root cause of the problem on my client side app?
Try use the new api key, not the legacy one. Got the same issue, when I change the key, the push notification is received in iOS client
Make sure both iOS and Android are registered on same Firebase application. In that case, your Server key on Firebase application will be the same for both iOS and Android. I think you are using different keys.
Got my point?
I'm currently implementing firebase phone Authentication, and can successfully implement the phone authentication using the firebase UI without swizzling, but from my research it seems that implementing firebase phone authentication without swizzling requires the user to allow notifications. I know that firebase sends a silent notification that does not need to be approved through allowing notifications but it seems the only way to get that notification without swizzling is to ask the user to allow notification. Does anyone know how or if its possible to do this without swizzling and without asking the user for notification permissions?
I have added to push notification certificates to firebase, and have added all the needed function listed in the firebase phone ui docs.
Without asking the user for to allow notifications this function listed from the phone auth docs does not get called (the user also has to select allow)
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Pass device token to auth
Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenTypeProd)
// Further handling of the device token if needed by the app
// ...
}
If this functions is not called the setAPNSToken is not set, I will not get the silent notification to continue with phone auth, and I will get the generic error
Authentication error: There seems to be a problem with your project's
Firebase phone number authentication set-up, please make sure to
follow the instructions found at
https://firebase.google.com/docs/auth/ios/phone-auth
I went ahead and disabled method swizzling as stated in the Firebase docs and then implemented all the required methods, the solution was that I needed to go the Capabilities of the app and then make sure Background Modes as well as Push Notifications (this was already enabled) were enabled. Then under Background Modes I had to enable Remote notifications.
Then I had to delete the app from my device and reinstall. This solved my issue and called the necessary functions for registering for notifications.