An iOS app has to use two firebase projects. I was super confused when I realized that the order of configuring the FirebaseApp seems to affect the messaging instance obtained by Messaging.messaging().
When I initialize the secondary app first, the Messaging delegate seems only to register registration token changes in the main app at func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String)
FirebaseApp.configure(name: AppDelegate.firebase_main_app_name, options: login_app_options)
FirebaseApp.configure()
Messaging.messaging().delegate = SOME DELEGATE OBJECT
But when I register the main app first, the messaging delegate seems to respond to only registration token changes in the secondary app.
When I register the main app first and
retrieve the FCM token by calling messaging_instance.retrieveFCMToken(forSenderID: AppDelegate.gcm_sender_id)
The token retrieved is different from the one from Messaging.messaging().fcmToken
But if I register the secondary app first then the two FCM tokens are the same.
The main firebase app can only send notification if I register the secondary app first.
I'm super confused by all this as this behavior isn't documented anywhere. What if I want to receive notifications from both firebase projects? Is there a way to tell which firebase project Messaing.messaging.delegate would reply to? Also, why does the order of configuring the two Firebase apps make a difference?
Related
I have a flutter social network app with firebase
I want to send notification to user when they get follow,like,comment or any activity
I know firebase cloud massaging do this but how
I want the exact code for this or some thing near with it
You can archive in 2 ways but in both ways you required user's fcm_token or device_token and firebase Server key.
Use this API - https://fcm.googleapis.com/fcm/send to send push notifications to specific users.
If you have own server
Manage via own server (secure & most preferred)
Crate your own API for send notifications to specific user. From your backend get that user's fcm-token & fire actual push API from your server.(firebase server key not save on mobile platform)
Do not include the server key anywhere in your client code. Also, make sure to use only server keys to authorize your app server.
If you don't have own server.
You need to add firebase sever_key in front-end means app code. (Less preferable)
Just call actual firebase push API from your app code.
Note: in both ways you required receiver fcm_token or device_token. Because you need to pass firebase server_key & this token in that API.
Reference links
1.official latest documentation for API link1
Another reference link2
API official doc - link3
I'm building an app and want to leverage AWS SNS for the push notifications. The documentation seems a bit spars.
I'm not using Cognito, and at the stage where I have got the deviceToken from Apple, the hasn't been a login in any case. The app uses AppAuth for the authorisation.
let defaultServiceConfiguration = AWSServiceConfiguration(
region: AWSRegionType.USEast1, credentialsProvider: nil)
AWSServiceManager.default().defaultServiceConfiguration = defaultServiceConfiguration
Obviously 'nil' doesn't work as credentialProvider. Is there anything I can give there to satisfy AWS?
Yes, you can.
For that, register the device tokens in a platform application endpoint, so you will receive an ARN reference for it, and then you attach it to your app user's entity at the end. This way you can directly push notifications for each individual user.
Here's a flow for the app token/ARN management:
More info here:
https://docs.aws.amazon.com/sns/latest/dg/mobile-platform-endpoint.html#mobile-platform-endpoint-pseudo-code
Similar solution applied here:
https://stackoverflow.com/a/32684226/3270938
I have setup background notifications , Hive (To store Notification Locally Using Adapter Class) and Setup a ChangeNotifier ModelClass to get Updates in UI.
Problem: I want to Add Notification data In Hive With ModelClass to get Notified in UI ,If Application is Not Active.
Now I need to access Provider.of(context) in my backgroundHandler which must be a static method where there is no context.
All I need to do is to perform an action according to the data in the background notification.
Same As In this Post
I'm using Firebase Cloud Messaging in my Dart/Flutter app. The code below updates a user doc with a retrieved android notification token.
FirebaseMessaging().getToken().then((token) {
_usersRef.doc(user.id).update({
"notificationAndroidToken": token,
});
});
I then read the notificationAndroidToken in my cloud functions. Works great except I had wrongly assumed the token would be invalid if the user had shut off their notifications (e.g., empty or null). What's the best way for determining if notifications are enabled for my app in cloud functions? I'm finding some hits in my searches but many are outdate or for a different dev environment.
The firebase_messaging package does not provide any method for checking if notifications are enabled by calling NotificationManagerCompat.areNotificationsEnabled on the platform. The awesome_notifications package provides such a isNotificationAllowed method.
I just wanted to confirm "didRegisterForRemoteNotificationsWithDeviceToken" is meant to be called everytime the application loads and my PHP server or application needs to deal with whether or not to resubmit to store in my database? Or is there something I am missing?
Thanks
James
First, you are not meant to call this method directly. Rather, you should call registerForRemoteNotificationTypes: on every launch of your app which then in turn calls application:didRegisterForRemoteNotificationsWithDeviceToken: which you must implement.
Second, yes, you are supposed to resubmit the token to your server every time. From the documentation:
By requesting the device token and passing it to the provider every time your application launches, you help to ensure that the provider has the current token for the device. If a user restores a backup to a device other than the one that the backup was created for (for example, the user migrates data to a new device), he or she must launch the application at least once for it to receive notifications again. If the user restores backup data to a new device or reinstalls the operating system, the device token changes. Moreover, never cache a device token and give that to your provider; always get the token from the system whenever you need it. If your application has previously registered, calling registerForRemoteNotificationTypes: results in iOS passing the device token to the delegate immediately without incurring additional overhead.