- Firebase Cloud Messaging (FCM). Supports both iOS and Android.
- Apple Push Notification service (APNs). Supports only iOS.
Common setup
This section outlines setup that needs to be done regardless of whether using FCM or APNs.Request for permission to show notifications
There are multiple ways of requesting a permission from user to display notifications. In Unity people generally use Unity Mobile Notifications to do so. Unity Mobile Notifications also has the added benefit that if you want to setup push notifications via APNs, it allows you to request the device token that is necessary to setup push notifications via APNs. If you for some reason don’t want to use Unity Mobile Notifications and you already don’t have another way of requesting the notification permissions, Theymes provides a convenience API to do so withTheymesSdk.RequestNotificationPermission().
Configuring iOS XCode project
Regardless of whether you use FCM or APNs, you need to enable push notifications and remote notifications (under background modes) capabilities in order for push notifications to work on iOS. The easiest way to set these up is by using Unity Mobile Notifications (UMN). When UMN is installed, you can find “Mobile Notifications” under the project settings. Toggle on the Enable Push Notifications setting. With this UMN will configure your XCode project with the required capabilities.Handling notifications when the game is in foreground
As outlined in the Notifications page, Theymes only shows text notifications to users when the game is in foreground if notifications are currently enabled withTheymesSdk.EnableNotifications().
Regardless of whether notifications are enabled or disabled, the in-game notification badges are always updated immediately when a push notification is received and the game is in foreground.
Handling tapped push notifications
When your game is in the background and user receives a push notification, the user can tap on the notification to directly open the support ticket within the game. In order for this to work correctly, you need to add a small piece of code to handle taps when the game comes to foreground. If you don’t add this, tapping the notification will open the game, but it will not automatically open the Theymes support overlay.You should not call
TheymesSdk.HandlePendingNotificationAction() before Theymes SDK has been initialized and the player info has been set as outlined in the Configuring the SDK. When HandlePendingNotificationAction() is called, the notification action is only handled if the logged-in player is the same player the notification was targeted for.Setting up FCM
First follow the instructions of Firebase Unity SDK to configure your Firebase project for Android and/or iOS and install the Unity FCM SDK. To configure push notifications for Theymes you need to:- Register the FCM device token with Theymes in the game client.
- Handle received notifications targeted to Theymes in the game client.
- Configure FCM push notifications in the Theymes application.
TokenReceived event and send the device token to Theymes with TheymesSdk.RegisterPushToken() in the callback.
The second step is done by adding an event listener to FCM’s MessageReceived event and pass the message data to TheymesSdk.HandleNotification(). This will only handle notifications targeted to Theymes, other notifications are ignored.
Here is an example of how to do first two steps. Keep in mind that adding the event listeners will also initialize FCM, which will trigger displaying a notification permission from the user, so you should do this in the appropriate place of your game initialization sequence.
- Select your game from the left navigation.
- Click “Settings” from bottom of the game navigation.
- Click “Push notifications”.
- Configure Firebase Cloud Messaging (FCM).
- Generate and upload your service account JSON credentials to Theymes.
- Use a webhook to your own back-office and forward the push notifications to FCM yourself.
Setting up direct integration to APNs
To setup service account JSON you need to either provide us an existing service account JSON or generate a new one in Firebase Console. To create a new key:- Open your project in Firebase Console.
- From top left, next to “Project Overview”, click the cog icon and select “Service accounts”.
- Click the “Generate new private key” button.
- Confirm and generate the new key.
- Store the file in a secure location.
In order for Theymes to send push notifications, the service account needs the
cloudmessaging.messages.create and firebase.projects.get permissions. These permissions are granted by roles roles/firebasemessaging.admin and roles/firebase.viewer.Setting up integration via webhook
When using a webhook, Theymes still normally collects the device tokens. When we need to send a push notification to a device, we will send a POST request to the URL you define with the exact payload in body that you need to forward to FCM API. It is outside the scope of this documentation how to create the webhook and how to sign the requests to FCM API, please refer to Google’s documentation for that. To setup the webhook in Theymes you need two things:- Credentials that Theymes will use to send a request to the webhook URL.
- The webhook URL.
Setting up APNs
To configure APNs push notifications for Theymes you need to:- Register the APNs device token with Theymes in the game client.
- Configure APNs push notifications in the Theymes application.
Register the APNs device token
Here is an example of how to get the APNs device token using Unity Mobile Notifications while requesting permissions to display notifications from the user, and then registering the device token with Theymes:- Swift
- Objective-C
- Select your game from the left navigation.
- Click “Settings” from bottom of the game navigation.
- Click “Push notifications”.
- Configure Apple Push Notification service (APNs).
- Generate and upload a .p8 private key file.
- Use a webhook to your own back-office and forward the push notifications to APNs yourself.
Setting up direct integration with APNs
To setup the APNs integration you need to:- A private key (.p8) with access to Apple Push Notifications service (APNs). You can create one in the Apple developer portal under Keys.
- Your private key’s Key ID. You can see this in the Keys page in Apple developer portal.
- Your game’s App Bundle ID (10 characters), eg.
com.yourcompany.game. - Your Team ID (10 characters). You can see this in the Apple developer portal.
- Whether to use production or sandbox environment. For development environment / local testing iOS uses the sandbox environment. For apps distributed via TestFlight or AppStore, production environment is used.
Theymes does not support the certificate-based (.p12) connection to APNs. In case you must use p12 certificates, you can setup the integration yourself and use webhooks in Theymes to deliver the push notifications via your back-office.
Setting up integration with webhook
When using a webhook, Theymes still normally collects the device tokens. When we need to send a push notification to a device, we will send a POST request to the URL you define. The request is made withContent-Type: application/json and the body is of the following format:
- Credentials that Theymes will use to send a request to the webhook URL.
- The webhook URL.