Problems integrating Exacttarget and FCM - android

We are integrating two new notifications SDK within the same app. Firebase and Salesforce Marketing Cloud (formerly ExactTarget).
Our IOS versions is working perfectly and no interference has been detected. We send notifications from both tools.
However, we are having problems with our Android versions. The behavior of some of our test-devices is:
Devices are correctly enrolled within the two platforms
Devices receive notifications without an apparent problem
Randomly speaking in terms of time, Salesforce marketing cloud can not notify devices anymore. They are still Opted In within that platform, and ET tries to send the message, but GCM responses with an Error,
InvalidRegistration,2016-11-22
04:00:00,TokenRejection,|ID|8|:(ServiceStatus,ServiceResponse,TrackingDate,FailureType,SystemToken)
Our guess (we’ve done a lot of tests) is that changes in tokens within GCM are producing that problems. We’ve tried to push into Salesforce a new token every time is renew (we get it from Firebase) using their method Registration.getInstance().setSystemTokenInCache(token), with no success up to now.

We did not solve it. We were in touch with Salesforce itself and were given some tips but none of them seemed to work:
Here's what we were told. Rather than creating two projects in Firebase and adjusting the google-services.json file, I just used the sender ID from one project. In your code, you keep the Marketing Cloud initialisation the same and the google-services.json file the same, you only need to change the call
FirebaseInstanceId.getInstance().getToken();
to
FirebaseInstanceId.getInstance().getToken("158036016337", "FCM");
where the first parameter is your sender ID (which is the same sender ID you use in your Marketing Cloud initialisation), and "FCM" is the scope.
What this did was, it returned two different tokens, one from Firebase and one from Marketing Cloud. Both tokens however had an 11 character prefix followed by a colon which was identical. I sent to pushes using both tokens and both worked well. I then subscribed for topics in Firebase
FirebaseMessaging.getInstance().subscribeToTopic("xxxxx");
And sent a push using the Firebase API to that topic and that worked as well. Sent some pushes from Marketing Cloud and that worked as well. I agree that you should test this however.

We solved the issue is a different way. We forced the notifications to be received in our Firebase service (by implementing intent rules in manifest). Then in onMessageReceived() method, we check if the notification from the ExactTarget with PushMessageManager.isMarketingCloudPush(Bundle). If this is true, we let Marketing cloud handle it via
MarketingCloudSdk.requestSdk(new
MarketingCloudSdk.WhenReadyListener() {
#Override
public void ready(MarketingCloudSdk marketingCloudSdk) {
marketingCloudSdk.getPushMessageManager().handlePushMessage(bundle);
}
});
else we handle it as Firebase push notification for our app.

Related

Using only one Firebase project, can I have different tokens for different apps on the same mobile device?

My setup consists of two android apps, that use the same backend. I was sending push notifications based on the deviceID, meaning if you installed both apps on the same device, the listener of app 1 would listen also to notifications intended for app 2, and hell would break loose.
I would like to know if Firebase can support this type of project.
So, does one Firebase project generates one Token per device per app, or only one Token per device?
If the latest, any tips on how to get this working?
Thanks in advance.
A registration (FCM) token corresponds to an app instance. AFAIK, different apps (unique by package name) should produce different tokens when getToken() is called regardless if it's using the same Firebase Project.
However, the usual (best?) practice is to have a separate project for every different app, then handle the multiple senders for each app.

How do I ensure that only my app is able to register and receive messages sent from FCM?

I am currently setting up a Firebase Cloud Messaging project. When adding apps to this project some credentials are automatically generated by FCM, e.g. the Server key as well as Android and iOS client keys.
For Android, I can download and use the google-services.json file to setup the client, i.e. registering for an FCM token and receiving push messages. But how do I restrict this so only my app can receive these messages?
I thought it would be the (auto created) Android client API key, so to test I've put an incorrect package name and SHA fingerprint in restrictions for the key. No effect, can still receive messages.
I then tried removing the API key as well as oauth client info completely from the google-services.json file, to confirm that the device then would not be able to receive messages. No effect, can still receive messages. All client info seems to be completely ignored, except for the app id (and the general project info).
So, I am really wondering what prevents reverse engineering of an app to extract the app id and general project info, and then receiving push messages in an entirely different app? I don't understand why the Android client API key, etc. is included in the google-services.json file, or why they are even created, if it is not used.
All the information in google-services.json is essentially configuration data that your app uses to find the Firebase services on Google's servers. You should not rely on knowing it, or lack of knowing it, as a security mechanism.
Instead you should send your messages in a way that ensures they are delivered only to the targeted recipients. A large part of this is sending messages to specific FCM Instance ID tokens. Firebase's Instance ID tokens are unguessable. Initially this registration token is only known on the client-side device where it is generated, and that device determines who to share it with.
By ensuring your client-side code only shares the token with your own server-side code, which then use it to target FCM messages, you can create a completely safe delivery environment where you fully control who can receive each specific message.
On the other side of this are FCM topics, which are a simpler mechanism for delivering messages to groups of users. Since any client can subscribe to any topic that it knows the ID of, topics should be used for delivering messages that require less securely targeted delivery.
I've been in contact with Firebase Support over the past week to shed light on this. It seems there is an important difference between the now deprecated Google Cloud Messaging (GCM) and Firebase Cloud Messaging (FCM), and it is currently not well documented.
With GCM it was possible to use and restrict e.g. the Android client API key with a package name and a SHA fingerprint. This is no longer possible with FCM. The keys are auto created when you add apps to your project in the Firebase console, and included in the google-services.json file, and you can add the restrictions to these under Credentials in APIs & Services, but it will not have any effect.
Please also note that the SHA fingerprint you can add in the Firebase project is only for Firebase Invites or Firebase Dynamic Links.
Be careful and have this in mind when you decide what to use the messaging service for, or when you migrate from GCM to FCM.
There is a feature request for this at Firebase but they currently have no timeline. There also a request now for an update of their documentation regarding this issue.

iOS app can't connect to Firebase IID service - Location Bound?

I am working on an app and the Android version implements Firebase for Instance ID, Cloud Messaging and Analytics. Everything is working properly in regards to obtaining the instance id and FCM token.
I also built a server API for sending notifications and data payloads to Android devices and in order to use the same methods in the iOS version I decided to use Firebase for iOS for the same purposes (Instance ID, Cloud Messaging and Analytics).
Setting up Firebase on iOS is well documented and I was able to set the environment for everything to work properly. However, when I run the app I got the following error in the console (which means that the instance id and FCM token were not retrieved):
....
[Firebase/InstanceID][I-IID003009] Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
[Firebase/InstanceID][I-IID003007] Failed to retrieve the default GCM token after 5 retries
Wait, I know there are other people complaining about the same issue here but this is a totally different case.
I thought that my setup was incorrect or missing something but I reviewed all the procedures and code and everything was 100% correct.
Where I am located (Damascus, Syria), some services are blocked by Google and can only be accessible via a proxy or a VPN. Therefore I setup a US proxy for both the device I am using for testing and the simulator and when I run the app everything works properly and I was able to get the instance id and the FCM token and log them in the console.
What is weird is that in the Firebase Console the analytics is showing the correct number of users even when the FCM token was not received which means that the communication with the Firebase service is not totally blocked. The only part which is not working (without a proxy) is fetching the FCM token.
My question is: Why this particular Firebase service is blocked in iOS and not in Android and can I do anything about it? Remember that I have no problem in getting the token in Android from the same location. Or is this a bug in Firebase and the service is not location bound?
I have no problem in connecting to Google APIs from my location for other purposes like Google Maps or getting information about an FCM token..etc. However, I noticed that the console is referring to iid.firebase.com instead of iid.googleapis.com.
Any help or suggestion in this regard will be appreciated because I want to make a decision whether I should keep trying to use Firebase in both platforms or if I should rely on Firebase for Android and the native APNs ways for iOS. Also, I want to know if my decision to implement Firebase was the correct one in the first place.
Thanks!

Can I use both GCM and FCM in my app?

I have an android project in which GCM is implemented. Back-end (server) is already coded suitably with GCM.
Now is it possible to add firebase (FCM) in my project and work in parallel with GCM? I cant migrate to FCM because it is impossible to change my back-end code as it is a big project and too much code is there. Has anyone done something like this?
Please help. Thanks in advance.
Though my particular case might be a bit specific, because the project I am involved in has a very specific backend, it seems to me FCM interoperates well with GCM, i.e you can have both in your app, GCM and FCM broadcast receivers / receiver services, and they will both work as well with no conflicts.
This has a huge advantage because you don't have to decide with migration at once, you can do this more gradually.
Well done, Google!
No, you can not use both FCM and GCM at same time. GCM is the old version and that it is strongly recommended to use FCM.
Why is Google Cloud Messaging (GCM) part of Firebase? How does it relate to Firebase Cloud Messaging (FCM)?
Google is investing in Firebase, making it our unified mobile
platform.
Over the last few years, we have expanded GCM to send messages to
multiple platforms beyond Android: iOS and Chrome. Firebase is known
for being cross platform, so FCM now makes a natural fit in the
Firebase suite of features designed for Android, iOS, and mobile web.
Another core value of Firebase is cross-feature integration. We are
adding the ability for other Firebase features to easily send messages
via FCM. For example, you can use Firebase Notifications to send
reengagement messages to your users.
We think that GCM will be even more useful to developers as an
integrated part of Firebase. You can still get the same great product,
now under a new name: "Firebase Cloud Messaging," or FCM for short.
Is GCM going to be deprecated?
We will continue to support the current version of GCM Android and iOS
SDKs because we know a lot of developers are using GCM SDKs today to
handle notifications, and client app upgrade takes time.
But all new client-side features will be added to FCM SDKs only moving
forward. You are strongly encouraged to upgrade to FCM SDKs.
You can get more details here
As per FAQ you don't need additional server configuration when you're migrating your client app from GCM to FCM, so just use FCM in your android app.
Here's the docs on how to migrate your app
I find the problem to use both GCM and FCM together. You will get to different deviceToken and one of these token get NotRegistered error.
For my FCM token always get NotRegistered error but the app is active and not uninstalled and my GCM token is valid and gets a push notification.

Smooth GCM to FCM transition

Anyone have experience with it? I'm investigating migrating, but as we already have the app released with GCM, with thousands of users and thousands of notifications daily, I'm reluctant for fear of disrupting existing service. Did anyone manage a smooth transition?
Specifically, in the tutorial (https://developers.google.com/cloud-messaging/android/android-migrate-fcm) step one is 'Import Google Project'. Is this a one-way operation? Will existing GCM server solution and deployed GCM apps continue to work?
Or is the best bet to create a new project, and maintain two server solutions until the GCM deployed apps are phased out?
Importing your Google project into Firebase is a one way operation, however this is not a destructive operation, your current project will have required APIs turned on and necessary API keys will be generated for use with Firebase, but you can still manage that project from the Google Developer console if you decide not to continue using Firebase.
Your present server solutions will continue to work as before. I would go with importing your project to Firebase. It will be much easier than having to migrate your backend to a new project.
note:
If you were using pre InstanceID tokens for device IDs then they will not work in the Firebase console or with topics. So you would have to maintain a mapping of which users you can send to using the Firebase console and/or topics. If your were using GCM with InstanceID then there is nothing to do since FCM also uses InstanceID. You can use the FCM REST API to send to ALL tokens, InstanceID or pre InstanceID.
Be sure not to use GCM and FCM libs in the same client app. You can find issues when generating tokens and handling received messages.
First test out, There are many things to take care in FCM.
Major issues :
White Notification Icon while app is in background or killed.
App hangs after opening closing multiple times.
Read these issues to decide:
Firebase push notifications update DB
https://stackoverflow.com/a/37626817/1507602
How to handle notification when app in background in Firebase
After Upgrading to Google Play Services 9.0.0, App Hangs in DynamiteModulesC
Notification Icon with the new Firebase Cloud Messaging system

Categories

Resources