FCM Notifications not arriving on iOS - ios

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.

Related

iOS APNS App and App Clip common push notification topic

I have push notifications setup for my app and it’s corresponding App Clip. Let’s say that the App has an AppID, com.X and the App Clip has the ID com.X.Clip.
I set the topic of the aps to com.X.Clip to send push notifications to my App Clip and it works properly. However, when I try to send push notifications to my App, I get the error DeviceTokenNotForTopic because the device token is for the AppClip and not for the app. Fixing the topic to com.X, solves the problem.
My question is, is there a way to set the topic to something common that can be shared by my App and the AppClip so that I don’t receive these errors? Otherwise I would have to also store which device tokens are for the app and which are for the clip which will increase storage costs.
Or perhaps there is another way?
Not sure if you figured it out, but I just asked a similar question here: How do I detect whether an iOS App Clip or Universal Link is running?
You can't combine them, but you can tell your server where to register the device token.

IONIC Push Notification - How to detect why notifications are not delivered on IOS?

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.

What are the requirements for FCM to work with Flutter on iOS?

I am working on getting Firebase Cloud Messaging to work with iOS via Flutter. I have followed the steps laid out here, here, and and here with no luck.
I am NOT using simulator, I am on an iPhone 8+ with iOS 11.4.1. I have installed all three APN certs in Firebase console. I have called FirebaseMessaging.requestNotificationPermissions(); and accepted the dialog. I am testing by sending messages through FCM console. I have my phone auth'd with Firebase (anonymous auth).
I do not receive messages with the app open or closed.
If anyone has any thoughts on what I might be missing, please assist. I would like to be able to make a bulletpoint list for others coming to Flutter/iOS/FCM to just follow without errors.
Alright, this is what I learned. Wish I had written this all down right when I got it working. But it should be helpful to someone.
Make sure Firebase is setup and working in your Flutter project.
Add firebase_messaging to pubspec.yaml
flutter packages get
Create/download your APNS key and upload it to Firebase console
Create/download your Provisioning Profile on Apple Dev website and double-click to install.
Use the important pieces of the snippet below
Send a message to all app users, or your messagingToken through Firebase console.
If you have a physical device running your app and you follow these steps, you should receive background notifications. You will not receive them in the foreground. If someone figures out how to get them in the foreground, let me know!
snippet
import 'package:firebase_messaging/firebase_messaging.dart';
FirebaseMessaging messaging = FirebaseMessaging();
messaging.configure(); // NECESSARY
messagingToken = await fb.messaging.getToken();
messaging.subscribeToTopic("general");
// this will launch a modal asking if you want to receive notifications
messaging.requestNotificationPermissions();
Sounds like you are missing some configuration steps in order to be able to send push notifications to your iOS App. Maybe the best that you can do is post more information about your configuration environment.
However, for the description that you give us, it can be an issue about one of the following options:
You need to configure the correct environment to send the push notification. If you install the app to the device directly from Xcode you need to use the Sandbox environment, but if your app is installed from AppStore or Testflight, you need to use Production. This is because both environment (sandbox and production) refers to different urls to send the push notification.
The deviceId related to the specific relation between your app and the current device is not stored. Remember, when you send a push notification you need to give which devices will receive that notification.
Please let me know if this responds your question or there is some that I've missing
EDIT
To handle foreground notifications you need to add the didReceiveRemoteNotification callback in order to get the title, message all the custom parameters of the JSON structure.
In this particular case, the plugin documentation says that you need three different callbacks, depending on the application status.
If the app is in FOREGROUND you need to use onMessage callback
If the app is in BACKGROUND you need to use onResume callback
If the app is TERMINATED you need to use onLaunch callback
However, this only make the parameters info available, you still needs to show them to the user in some custom way (for example WhatsApp or Facebook Messenger can show you the new chat message if you are in a different conversation as a independent bubble on top of the view, or this new message is added to the bottom of the conversation if it belongs to the current chat).

App Store rejection due to Firebase phone auth

Our app uses Firebase phone auth. The App Store review has rejected the app due to pushes being required:
Guideline 4.5.4 - Design - Apple Sites and Services
We noticed that your app requires push notifications in order to function.
Specifically, we noticed if the Push Notifications setting was not enabled on our device, we encountered an error message after entering our phone number within the app.
Next Steps
Push notifications must be optional and must obtain the user's consent to be used within the app.
And they've also attached the screenshot that depicts Firebase error "Remote notifications and background fetching need to be set up for the app [...]"
Firebase documentation states that APNs notifications are absolutely required for phone auth to function:
https://firebase.google.com/docs/auth/ios/phone-auth
To use phone number authentication, your app must be able to receive APNs notifications from Firebase. When you sign in a user with their phone number for the first time on a device, Firebase Authentication sends a silent push notification to the device to verify that the phone number sign-in request comes from your app. (For this reason, phone number sign-in cannot be used on a simulator.)
However App Store review guidelines state that Push Notifications must not be required in order for the app to function: https://developer.apple.com/app-store/review/guidelines/
4.5.4 Push Notifications must not be required for the app to function, and should not be used for advertising, promotions, or direct marketing purposes or to send sensitive personal or confidential information.
Users need to sign in before they can use the app (the app is about sending digital GIF invitations to your guests and sharing photos), which is why Push Notifications are basically required for the app to function, if the sign in method is Firebase phone auth.
We have tested the app a lot, and the authentication works without a problem when push notifications are enabled (on real devices, both in distribution Ad Hoc builds with production environment and development builds with sandbox environment).
Come to think of it, how did App Review team even disable Push Notifications? The notification center setting does not stop actual pushes, it just doesn't display them.
We have tested with this setting off, and firebase phone auth works fine, pushes are still coming through as expected.
I am very surprised with this issue, as Firebase is a huge service provider. Did anyone else encounter this issue?
Are there plans to remove APNs requirement for phone auth? Is there maybe some other way to use Firebase phone auth without pushes?
Firebaser here. We have released an updated Firebase Auth SDK, 4.2.0, as Leetmory mentioned, which should hopefully resolve these issues going forward.
The issue was caused by the fact that the Firebase Auth SDK using APNs to validate the request - this is to minimize the risk of SMS spam abuse or similar. The validation uses a silent APNs notification, so doesn't require explicit user consent for iOS 8 and above. However, this still failed if APNs was completely disabled, as in this review case.
The 4.2.0 release introduced the facility to use a reCAPTCHA prompt inside an SFSafariViewController (or webview for older iOS) to prevent abuse if APNs isn't available. We don't expect this to happen very much, but it accounts for the unusual state encountered here. It also enables support for testing Firebase Phone Auth on the simulator!
You'll notice there is a new uiDelegate parameter on the verifyPhoneNumber method. In most cases you wont need to use this, but it is part of the fallback verification.
What you will need to do, if you haven't already, is add the REVERSED_CLIENT_ID (from the GoogleService-Info.plist) as a custom URL scheme. This will allow the reCAPTCHA view to return validation to your app.
There is a gotchas to be aware of in the current version though:
In the callback from verifyPhoneNumber you'll need to redispatch to the main thread, using DispatchQueue.main.async {} - this will be fixed in the next version of Firebase Auth!
Other than that, things should work as normal! We definitely recommend supporting silent push where ever possible to ensure the best user experience.
For a full walk through, see the full Phone Auth developer guide.
UPD: Firebase 4.2.0 has rolled out, which fixes the issue. You will need to add your reverse-client-id which looks something like this: com.googleusercontent.apps.123456-abcdefg99 to URL schemes in your Info.plist, and you are set.
To find this
value, open the GoogleService-Info.plist configuration file, and look for the
REVERSED_CLIENT_ID key.
Firebase support has confirmed this bug and has given the response to this issue:
to me
Thank you for the detailed information Leet. This is indeed an odd situation, and our Phone Auth engineers are taking a look. I'll get back to you as soon as I have an answer.
Best,
Jeff
to me
Hi Leet,
Our engineers are working internally on a long-term fix for this, but in the meantime, would like to meet with you to see if we can figure out a workaround.
It appears that there is indeed a bug in Firebase phone auth / Firebase UI.
I contacted Firebase support and here's an excerpt:
In terms of the concern around users disabling push notifications - Disabling push notification for the app by the user does not normally prevent users from signing in using their phone number with Firebase Auth. Our requirement is that the app must set up and enable push notification, not the user. Regardless of if the user accepts or declines your app's push notification prompt phone auth will continue to work since we use silent pushes that don't require any action from the user.
I researched further and found that silent push notifications do indeed arrive to the device even when the user explicitly disables push notifications. To disable silent push notifications you would need to go to Settings -> Your App -> Background Refresh to disable it. See Is Silent Remote Notifications possible if user has disabled push for the app?
So you can tell the App Store Review team that your login will only work when Background Refresh is enabled. I don't believe this violates their terms.
EDIT
After some testing, it appears that phone auth can work when Background Refresh is disabled. However, it works for me because Firebase already has access to my APNS device token. I have found no way to disassociate my device token from Firebase - they provide no API for it. This unfortunately makes it impossible to test the scenario where a new user disables Background Refresh and Remote Notifications before doing the phone auth which I believe may be the cause of the error.
EDIT 2
I can confirm that on a fresh device with a fresh install of our app, if you disable Background Refresh then Firebase Phone Auth will not work. Once you enable it, it will work again.
The reason is that the SDK likely calls [[UIApplication sharedApplication] registerForRemoteNotifications] which is ignored by the system if a user manually disables the Background Refresh and Notifications settings.
Unfortunately there is no workaround until Firebase releases a new SDK which does not require APNs.

Query OneSignal server from device to get info about push notifications received while app was closed

I'm using OneSignal Swift in a native iOS application. So far i'm able to handle all kinds of push notification cases (foreground/background) except one. When user has force closed the application from "task bar switcher".
I'm using 'content-available':'true' in all my notifications through OneSignal in order to wake up my app and start running code the exact moment the notification is received. So far so good everything is working as expected.
When the app is closed and push notification arrives, if user taps it, then handling with OneSignal works with OSHandleNotificationActionBlock callback.
The problem though is if user doesn't tap and just opens through application icon, then notification data are completely lost. Online reference dictates that the correct way of handling this (what most apps like Facebook do), is query tour APNS (OneSignal in my case) for unhandled notifications and re-fetch them on application start. So the question is how to do that from OneSignal iOS native SDK? Is it possible? There is ofc the REST Service -which might be the case- but users are clearly discouraged to call the API from inside client application. An app key is necessary which shouldn't be saved in device's keychain apparently for security reasons(??)...

Resources