Upgrade Guide to FCM: Unity¶
As announced by google, the support for GCM will end at 2019/4/11. Therefore in case you are still using GCM, it is recommended to follow the FCM transition procedure described below soon.
Transition procedure¶
Transition of a Google Cloud Platform project to the Firebase Console¶
From your Firebase Console create a new project and select your former GCM project:
Please confirm that your Google Cloud Platform project number and your Cloud Messaging sender ID are Identical. You can find your Project number under Google Cloud Platform > IAM & admin > Settings
The sender ID can be found in your Firebase Console under Settings(icon) > Cloud Messaging:
Setup FCM¶
Refer the steps in Register the App to download the
google-services.json
.Refer the steps in Generate Private Key and Register Server Key on Repro to register your Server Key.
Updating of the Repro Unity Package¶
Perform a SDK update to at least version 4.1.0 of the Repro Unity SDK according to Unity Package Upgrade Guide.
Installation of the Firebase SDK¶
Delete dependencies related to GCM¶
Please delete the file play-services-gcm-x.x.x.aar
located at Assets/Plugins/Android/libs
.
Import of the Firebase Unity Package¶
Refer to the official Firebase documentation and install FirebaseMessaging.unitypackage as well as FirebaseInstanceId.unitypackage.
Warning
In case you are using Repro Unity Package <= 6.5.0 or Firebase Cloud Messaging for Unity <= 7.2.0, then FirebaseInstanceId.unitypackage must be imported as well.
Warning
After installing the Firebase packages, the AndroidManifest.xml that you have setup in Specify Application Class should have been overwritten. Therefore you will have to once again adjust your AndroidManifest.xml
file.
Also modify your AndroidManifest.xml as instructed below¶
Change io.repro.android.GCMReceiver
to io.repro.ReproReceiver
like this:
<receiver
- android:name="io.repro.android.GCMReceiver"
+ android:name="io.repro.android.ReproReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="YOUR_PACKAGE_NAME" />
</intent-filter>
</receiver>
Registration ID acquisition method related changes¶
Obtain your FCM Registration ID via the method described here and pass it to Repro.SetPushRegistrationID()
. Furthermore you must delete the first argument of Repro.enablePushNotification
since it is GCM related and not needed anymore.
using UnityEngine;
public class MyBehaviour : MonoBehaviour {
void Start () {
...
#if UNITY_ANDROID
- Repro.EnablePushNotification(SENDER_ID);
+ Repro.EnablePushNotification();
+ Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
+ Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
#endif
...
}
+#if UNITY_ANDROID
+ public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token) {
+ Repro.SetPushRegistrationID(token.Token);
+ }
+
+ public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e) {
+ ...
+ }
+#endif
}