All Collections
Portal Pages
Design | Notifications | Settings
Design | Notifications | Settings
Jason Liang avatar
Written by Jason Liang
Updated over a week ago

Google Firebase

Prerequisites

Step1: Configure FCM cloud messaging server-key to brainCloud

  • Navigate your browser to the Firebase console and select your project. Click the Settings Icon -> “Project settings” in the top left nav bar.

  • Select “Cloud Messaging” and copy the Server Key.

  • Navigate to the brainCloud development console Design | Notification | Settings page, click Edit Settings.

  • Paste this key into Google Play API key field, and set expiration days for this key.

Step2: Register a notification token to your device via your app

  • Use the Keystore file of your Android app to create a fingerprint SHA1 and add it to your Firebase project.

  • Download google-services.json file and add it to your app root folder (for Unity will under Assets folder). This file contains most of the credentials you’ll need to connect your app to Firebase.

  • Follow the SDK Instruction to finish settings for your app. (If you are using the Unity Firebase Messaging package, after importing, your Assets folder should similar to the structure below)

  • In your app, after authenticating a user with brainCloud, you will need to register the Firebase Registration token with brainCloud. Specifically, you’ll want to call the RegisterPushNotificationDeviceToken() method to pass in the token.

  • If you are using Unity SDK, your code should be similar to the following.

        void InitializeFirebase()
    {
    Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
    Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
    Firebase.Messaging.FirebaseMessaging.SubscribeAsync(topic).ContinueWithOnMainThread(task => {
    LogTaskCompletion(task, "SubscribeAsync");
    });
    DebugLog("Firebase Messaging Initialized");
    Firebase.Messaging.FirebaseMessaging.RequestPermissionAsync().ContinueWithOnMainThread(
    task => {
    LogTaskCompletion(task, "RequestPermissionAsync");
    }
    );
    isFirebaseInitialized = true;
    }

    ...
    public virtual void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token)
    {
    DebugLog("Received Registration Token: " + token.Token);
    firebaseToken = token.Token;
    AddStatusText("Received Registration Token: " + token.Token);
    }
    ...
    public void OnRegisterToken()
    {
    _bc.PushNotificationService.RegisterPushNotificationDeviceToken(Platform.GooglePlayAndroid, firebaseToken, authSuccess_BCcall, authError_BCcall);
    }
    ...

  • If Java Android studio

      FirebaseInstanceId.getInstance().getInstanceId()
    .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
    @Override
    public void onComplete(@NonNull Task<InstanceIdResult> task) {
    if (!task.isSuccessful()) {
    Log.w(TAG, "getInstanceId failed", task.getException());
    return;
    }

    // Get new Instance ID token
    String token = task.getResult().getToken();
    _bc.GetWrapper().getPushNotificationService().registerPushNotificationToken(Platform.GooglePlayAndroid, token, theCallback);
    }
    });

Step3: Test

  • Run your app, authenticate an end-user to brainCloud and call RegisterPushNotificationDeviceToken() method to register device token.

  • Once your test device is registered the notification token to brainClound from your app, you can check it from the User Monitoring | User Summary page.

  • Hit Send Notification button from the above page will pop-up a Send Notification window, fill some text and Click Send. Your test device should receive this notification from brainCloud. You can always use brainCloud Push Notification methods to test too.

  • Note that the above example is the settings for Android, however, the configuration steps are almost the same, for detail of setting up iOS with FCM, please visit Firebase documentation.

iOS APNs

Prerequisites

  • Must have an iOS developer account

  • In order to configure brainCloud to send notifications to your iOS app, you will need to provide a p12 certificate file. Follow these steps to create a p12 file for your app.

brainCloud Portal Configuration

  • Log into the brainCloud portal

  • Navigate to Notifications | Settings in the Design tab for your app

  • Click on the edit button for the Apple notification settings

  • Upload your p12 file and enter the password that was used to create the p12 file into the dialog

  • Notice that once you’ve done that, the type of certificate shows up (production/sandbox) as well as the expiry date

Unity Code Example

  • Check this article for the details.

Did this answer your question?