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.
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.
I've added Push Notification to my IONIC App using this tutorial: Using Push Notifications with Firebase in an Ionic + Angular App.
For Android all works fine, but on IOS notifications are not delivered. In my Firebase console there is an information that notification was sent, but nothing appeared on my IPhone. The app is installed by TestFlight (Internal Tests).
Questions would be:
How can debug or somehow detect where might be the problem?
If there is no way to check it, maybe there is a list of common problems with that?
Check if iOS push notifications permissions are enabled
Check to see if you receive a push notifications token when you run your app (it doesn't work on simulator, must be real device)
Register push notifications key on your apple developer account and add the key to your firebase app.
Push notifications on iOS is a bit tricky. This tutorial helped me: https://devdactic.com/push-notifications-ionic-capacitor/
Check on the client that it sends a push token to the server.
Check on the server if any errors are reported when pushes are sent to apple.
Check in the console logs whether and pushes appear on your client device.
Check in the app if any push notifications are received.
In addition to following the advice already listed and assuming that you have followed the linked tutorial in detail, what helped me to understand the problems related to my experience with push notifications is to check the validity of the token received from the
// On success, we should be able to receive notifications
PushNotifications.addListener('registration',
(token: PushNotificationToken) => {
alert('Push registration success, token: ' + token.value);
}
);
is to contact this link https://iid.googleapis.com/iid/info/{{Token}}?details=true by entering your received token. If the response contains an error your configuration is incorrect and the error should be found in the changes applied to AppDelegate.swift. Furthermore, I noticed that not always the listener to capture the token does not always activate after a registration and I had to insert in my app also the #capacitor-community/fcmplugin that offers the method
FCM.getToken ()
.then ((r) => alert (`Token $ {r.token}`))
.catch ((err) => console.log (err));
which always returns the token according to my tests, this solution has been applied only for iOS, moreover this plugin also allows you to manage topics efficiently. It's definitely not a clean solution but for me it solved a problem I've been struggling with for days. The last advice I can give you is to pay attention to the activation and deactivation of the listners and to try to use setTimeout () to understand if your failure to work derives from an incorrect initialization of the resources and if these must be moved to the app states where the resources required by the various methods are available.
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.
I have an app to work on. And I need to know if there is already some push notifications before the app is opened. Is there a way to solving the issue?
Thanks
You can't push a notification to a device when your application hasn't been opened at least once - the user has to authorize push notifications and you need get the push token value - returned after calling registerForRemoteNotifications - and send it to your server.
There's no guarantee that your app will see multiple push notifications if they all arrived when the application wasn't running. Often you'll just see the most recent notification. You should store all of the notifications on your server and have your application request them when it becomes active if there's at least one notification waiting for you.
Once you've registered for notifications you need to setup didReceiveRemoteNotification method in your AppDelegate. There you can handle any information received from a Push Notification. Here's a link to there relevant documentation.
I'm trying to get push notifications to my iOS app using PushKit, but I never get a callback when registering for the notifications.
I actually DID both register ok and received notification earlier, but I must have managed to screw something up or gotten blacklisted by Apple.
I can still send the notifications fine (to sandbox apps), but I never get the notifications and I assume this has to do with the missing callback when registering in the app. Sending to production renders an "INVALID TOKEN" error which I assume is fine as the app isn't in the app store.
Any ideas on what's going on here ? Please ask for more info if I missed something.
gist with AppDelegate/settings/console output
I had the same issue. As #sugarngp mentioned in his comment above, my issue is that my PKPushRegistry object was getting deallocated. Once I made it an instance variable of my AppDelegate it fixed the issue.