FirebaseException: The operation couldn't be completed. No APNs token specified before fetching FCM Token - ios

I'm not sure what else I need to do to get the FCM Token. Perhaps I'm missing a step. Below are the details of my current setup.
This is an Unity iOS build calling GetTokenAsync.
Firebase.Messaging.FirebaseMessaging.GetTokenAsync();
However, I'm getting an exception.
FirebaseException: The operation couldn’t be completed. No APNS token specified before fetching FCM Token
I've generated an APN Key for push notification and uploaded to Firebase, but I'm not sure do I need to included it somehow with Xcode?
I've enabled Background Modes.

There are multiple reasons this could be happening. The following instruction steps are included in the Set up FCM for Unity Guide.
Try each of the following (if you haven't already):
Enable Push Notifications in Xcode under App > Capabilities
Add UserNotifications.framework in Linked Frameworks and Libraries
Switch Push Notifications to On in capabilities
Make sure method swizzling is enabled
If this doesn't work then look through the logs before and after the message you are getting above and see if there are earlier messages relating to warnings or failures with FCM or APNS.
Please tell me how it works out for you.

Related

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.

FCM notifications sent but never received in iOS

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?

Firebase Notifications triggers wrong delegate on iOS 10

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.

GCM (Google Cloud Messaging) for iOS apps

I am working on an iOS app, in which my client is asking for implementing GCM (Google Cloud Messaging) on iOS platform. I need to be sure if it can be done on iOS. As we use APNS for Push Notifications in iOS.
Can anyone suggest me about this.
Thanks In Advance.
Please check this link it contains all steps to integrate GCM in iOS and requirement is you need to set up CocoaPods dependencies.
https://developers.google.com/cloud-messaging/ios/start
https://developers.google.com/cloud-messaging/ios/client
Its a late answer.But I just started working on GCM on iOS.SO I thought to answer this question as it might help someone.
The following flow chart gives a brief idea on GCM.
GCM can can be used to send updates to a single registrationID,a group
to registrationIDs,or we can register a topic in the GCM server and we
can send updates to all the devices subscribed to that particular
topic.
Just follow the steps and you will find GCM integration easy.
STEP 1: Do watch this video completely : https://www.youtube.com/watch?v=gJatfdattno This gives the basic idea on how GCM works.
STEP 2
Goto this link: https://developers.google.com/cloud-messaging/ios/client
This shows clearly how you should configure the project.The main and important part is properly configuring the GCM config file.
You just have to upload apns certificate (developer and production) and get the gcm config file and add it to your project (drag and drop to your project navigation pane).
The following code which you should call in the didFinishLaunchingWithOptions will automatically fetch the _gcmSenderID from the config file.
_gcmSenderID = [[[GGLContext sharedInstance] configuration] gcmSenderID];
Another important part is properly setting the kGGLInstanceIDAPNSServerTypeSandboxOption to yes or no in didRegisterForRemoteNotificationsWithDeviceToken depending on which environment you are using the code(development or production).ie; kGGLInstanceIDAPNSServerTypeSandboxOption key should be YES if you are using it for testing.
Here is a sample quick start project for you to start with.(both swift and objective-C).Everything is well explained in this sample app.
Let me know if you have any doubts.
Regarding actual communication, as long as the application is in the background on an iOS device, GCM uses APNS to send messages, the application behaving similarly as using Apple’s notification system. But when the app is active, GCM communicates directly with the app
.
The data payload and notification payload are both applicable on iOS & Android. On iOS the difference is that notification payload is sent through APNS while data payload is sent through GCM's own connection which is only there when app is in foreground.

How new GCM handles APNS feedback?

I was trying out new GCM feature to send notifications to iOS devices. Everything worked very smooth except the feedback message. I assume after GCM sends message through APNS, GCM also calls feedback service of APNS to get the invalid tokens. Next time when we use the same device token to GCM, it should respond with error message. I tried several times after uninstalling the app, but never received an error message from GCM. Each time it shows success message. What went wrong here?
Note: If you are not familiar with new GCM features, please do not blindly answer to this.
I think the problem here is with the environment. I am using developer certificate to test the notification. APNS may not be giving any details for developer environment. Hope it will work in production.
Updates
Support from Google gave following details.
We did some digging, it seems that is how things are being handled by APNS:
When last sandbox app is removed from the device, device disconnects from APNS sandbox and not able to receive pushes/provide feedback anymore. Thus, APNS feedback doesn't register that the device has been uninstalled.
If you install another push-enabled sandbox app on the device, which would force device connection to APNS again. And we checked that under this circumstance, we get notified that the device has been uninstalled and return NotRegistered to our client.
APNS feedback service is not instantaneous. GCM does poll APNS feedback service but in my experience it was a bit delayed (not sure if it was APNS's delay or GCM's delay).
You should wait for some time and then try to use an old registration token and you should see a "Invalid Registration Token" error.

Resources