GetSocial Notifications on Unity

Prerequisite

Setup Unity Push Notifications

Android

GetSocial supports sending push notifications via Firebase Cloud Messaging (FCM) or Google Cloud Messaging (GCM).

  1. Follow FCM official guide (or GCM official guide) to setup push notifications in your app.

    CDM Permissions for GCM

    If you’re using Google Cloud Messaging for Push Notifications, don’t forget to add CDM permissions to your AndroidManifest.xml with clicking “Add CDM Permissions(GCM only)” in GetSocial Settings in Unity Editor.

  2. Login to the GetSocial Dashboard.

  3. Go to the “App settings” section → “Notifications” tab.
  4. Enable Android notifications by clicking on the switch and fill in “API Key” and “Sender ID” values.

    You can find “API Key” (Server key) and “Sender ID” in your application settings in Firebase developer console.

    GetSocial Dashboard - Enable Push Notifications

  5. Select what kind of notifications users will receive:

    GetSocial Dashboard - Notifications Type

  6. Press “Save” button in the bottom right corner.

  7. In your Unity project. Go to menu bar → GetSocial → Edit Settings.
  8. In Android Settings section ensure that push notifications are enabled:

    Setup Push Notifications iOS in Unity Editor

iOS

Generate Push Notification Certificate

  1. Open Apple Developer Portal;

  2. Log into your account;

  3. Open “Certificates, Identifiers & Profiles”;

  4. Find “App IDs” in “Identifiers” section and find your application;

  5. Click “Edit” and scroll to “Push Notifications” configurations;

  6. Click “Create Certificate…” for Development and Production.

  7. Follow the instructions how to create certificate and download it.

Export Server .p12 Certificate

Double click on downloaded .cer file (your certificate), it will add it to your Keychain Access and open. Click on “Certificates” section, find your certification, and export it with clicking “Export Apple Development/Production iOS Push Services”, create a password for your certificate and save it somewhere on the disk.
Do it for both Production and Development certificates.

Adding push notification configs to the dashboard

  1. Login to the GetSocial Dashboard.
  2. Go to the “App settings” section → “Notifications” tab.
  3. Enable iOS notifications by clicking on the switch and upload certificates, downloaded in previous section.

  4. Select what kind of notifications users will receive:

    GetSocial Dashboard - Notifications Type

  5. Select “Sandbox” if your application is using development push notifications, or “Production” for development.

  6. Press “Save” button in the bottom right corner.

  7. In your Unity project. Go to menu bar → GetSocial → Edit Settings.

  8. In iOS Settings section ensure that push notifications are enabled and push notifications environment is correct:

    Setup Push Notifications iOS in Unity Editor

Enable/disable GetSocial Notifications on the Client Side

By default GetSocial SDK automatically registers itself for push notifications during initialization. To prevent this behaviour you have to open “GetSocial” setting in your Unity Editor, and in “General Settings” find “Push Notification” and disable “Register Automatically” checkbox.

Setup Push Notifications in Unity Editor

In this case GetSocial will not automatically register your device on our Push Server. But you still can register for push notifications manually:

1
GetSocial.RegisterForPushNotification();

Handle Click on Push Notifications

GetSocial UI

If you’re using GetSocial UI, our respective view will be opened on click on push notifications: if someone liked your activity or commented under your activity, this activity will be shown on application start.

Important

If GetSocial View is opened automatically by GetSocial UI, you can not set custom title, UiActionListener, action button handler etc. In this case we recommend you to override default behavior and open GetSocial View by yourself.

Notification Action Listener

To handle notification click in your code, we provide NotificationActionListener, you can set it in Awake method of your MonoBehaviour derived class.

1
2
3
4
GetSocial.SetNotificationActionListener (action => {
    bool isHandled = processAction(action);
    return isHandled;
});

This method will be called if your Application was started from GetSocial notification click.
You return a bool: true, if notification is handled by your own, or false if not, so it will be handled by our library.
For example, if you want to prevent of showing GetSocial Activity Feed UI on notification click:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
bool ProcessAction(NotificationAction action) {
    switch (action.Type) {
        case NotificationAction.ActionType.OpenActivity:
            // add custom logic here
            Debug.Log ("Activity action received");
            return true;

        default:
            return false;
    }
}

In this case you’re showing something you’d want to show about the activity and GetSocial UI won’t be shown.

Tip

If you are not using GetSocial UI, we recommend to handle notifications by yourself - better user experience would be to react to notification actions.

Customize Notification Icon (Android only)

By default GetSocial SDK will use application icon as notification icon.

There are two ways to customize the icon. First option is to put image with name getsocial_notification_icon into Plugins/Android/res/drawable/ folder. Second option is to set icon resource name in Android Manifest meta data:

1
2
3
4
5
6
7
<application ... >
    ...
    <meta-data
        android:name="im.getsocial.sdk.NotificationIcon"
        android:resource="@drawable/ic_notification_custom" />
    ...
</application>

As a result all notifications coming from GetSocial SDK will use custom icon:

Customized Notification Icon

Give us your feedback! Was this article helpful?

😀 🙁