Push Notification (Unity)¶
Settings for Push Notification¶
See Settings for APNs Certificate (iOS) and Settings for FCM (Android) to setup.
Add Firebase Unity SDK¶
See the official document of Firebase to import FirebaseMessaging.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 importing Firebase packages, the AndroidManifest.xml edited when installing Repro may be overwritten by the settings from Firebase. Therefore, please edit AndroidManifest.xml
again after import.
iOS Platform¶
Depending on the Unity version, installation flow differs for the iOS Platform. Please select the right method based on your Unity version.
Passing the device token to Repro with Unity versions below 2019.4¶
Here we use Unity's official API in order to acquire the token. Please refer to the official documentation for further details.
Turn on Push Notifications from Capabilities in Xcode.

Register a device to APNs in the Start()
method of your class derived from MonoBehaviour
. In the Update()
method of the same class set the device token for Repro.
using UnityEngine;
#if UNITY_IOS
using NotificationServices = UnityEngine.iOS.NotificationServices;
using NotificationType = UnityEngine.iOS.NotificationType;
#endif
public class MyBehaviour : MonoBehaviour {
bool tokenSent;
void Start () {
...
#if UNITY_IOS
tokenSent = false;
NotificationServices.RegisterForNotifications(
NotificationType.Alert |
NotificationType.Badge |
NotificationType.Sound);
#endif
...
}
void Update () {
#if UNITY_IOS
// Send device token to Repro
if (!tokenSent) {
byte[] token = NotificationServices.deviceToken;
if (token != null) {
string hexToken = System.BitConverter.ToString(token).Replace("-", "");
Repro.SetPushDeviceToken(hexToken);
tokenSent = true;
}
}
#endif
}
}
Passing the device token to Repro with Unity version 2019.4 and above¶
The Mobile Notifications package should be used to acquire the token.
With the halp of the Unity Package Manager the Mobile Notifications package should be installed. Installation instructions can be found here .
Then enable Enable Push Notifications
in the Unity Editor at Project Settings > Mobile Notifications.

Finally, handling of the device token can be implemented in a new class derived from MonoBehavior
inside of the Repro.SetPushDeviceToken()
method.
#if UNITY_IOS
using Unity.Notifications.iOS;
#endif
...
public class MyBehaviour : MonoBehaviour {
public void Start()
{
...
#if UNITY_IOS
StartCoroutine(RequestAuthorization());
#endif
}
#if UNITY_IOS
IEnumerator RequestAuthorization()
{
var authorizationOption = AuthorizationOption.Alert | AuthorizationOption.Badge | AuthorizationOption.Sound;
using (var req = new AuthorizationRequest(authorizationOption, true))
{
while (!req.IsFinished)
{
yield return null;
};
Repro.SetPushDeviceToken(req.DeviceToken);
}
}
#endif
}
For more information on the settings, please see here .
Android Platform¶
Edit AndroidManifest.xml
¶
Register receiver¶
Replace "YOUR_PACKAGE_NAME" with your application's package name in the following snippet, and add it to your AndroidManifest.xml inside of <application>
tag.
<receiver
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>
Setup Notification Channels¶
Since Android O, Notification Channels were introduced to help users manage their notifications.
To set the notification channels in Repro SDK, please specify the following: ID, channel name, description for users, and with or without badge display.Replace the value
, resource
within the XML below with the desired value, and add the <application>
tag into the AndroidManifest.xml.
Warning
If the targetSDKVersion of your application is greater than or equal to 26, please note that channel id and name are required or the SDK won't show notifications sent from Repro while running on devices with Android O or later.
The
ChannelId
must be a string, liketest ID
, instead of an integer or decimal. If you specify a value other than a string, channel IDs will not work and push notifications won't be displayed.The
ChannelName
andChannelDescription
must be configured using theandroid:resource
attribute.
<meta-data
android:name="io.repro.android.PushNotification.ChannelId"
android:value="YOUR_CHANNEL_ID">
</meta-data>
<meta-data
android:name="io.repro.android.PushNotification.ChannelName"
android:resource="@string/YOUR_CHANNEL_NAME">
</meta-data>
<meta-data
android:name="io.repro.android.PushNotification.ChannelDescription"
android:resource="@string/YOUR_CHANNEL_DESCRIPTION">
</meta-data>
<meta-data
android:name="io.repro.android.PushNotification.ShowBadge"
android:value="true">
</meta-data>
If the channel of the specified id does not exist, it will be created automatically by the SDK based on the information provided in AndroidManifest.xml. If there is an existing channel with the specified id, the SDK will use it.
The SDK will update the channel name and description and channel importance of the existing channel being used by the SDK.
The SDK will ignore the settings above when the targetSDKVersion of your application is 25 or below, or when the application is running on devices with versions earlier than Android O.
Note
Notification Channels were introduced as a standard feature in Android O. For the details, please refer to this page.
Customize Icon and Background Color¶
When customizing the icon and the background color displayed in the notification area for devices with Android 5.0 or above, add the XML construct below inside of the <application>
tag in your AndroidManifest.xml. This setting will be ignored with devices under Android 5.0, and the notification area will use the application's icon as well as the system's default background color.
<meta-data
android:name="io.repro.android.PushNotification.SmallIcon"
android:resource="@drawable/YOUR_ICON_ID">
</meta-data>
<meta-data
android:name="io.repro.android.PushNotification.AccentColor"
android:resource="@color/YOUR_COLOR_ID">
</meta-data>
Send Registration ID to Repro¶
In the Start() method of the class inheriting MonoBehaviour, call Repro.EnablePushNotification()
.
When the Registration ID is refreshed, you can retrieve the new Registration ID by this method. Pass the retrieved Registreation ID to call Repro.SetPushRegistrationID()
.
using UnityEngine;
public class MyBehaviour : MonoBehaviour {
void Start () {
...
#if UNITY_ANDROID
Repro.EnablePushNotification();
#endif
#if UNITY_ANDROID
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
}
After finishing the above implementation, see Create Push Notification.
Customize the behavior when receiving messages¶
The Repro Unity SDK does currently not support customized behavior for received push notifications.
Option: Using Universal-Links/App-Links¶
It is possible to custom handle the opening of Universal-Links (also called App-Links) when Push Notifications or In-App Messages are tabbed. (For simplification from now only called Universal-Links.)
Please follow the examples below in order to add a custom Universal-Link callback handler which is executed every time an Universal-Link would be opened from a Push-Notification or In-App Message.
How to register a regular expression to match Universal-Links.¶
In order to use Universal-Link callbacks, a regular expression based url matcher must be added.
Note
When a pattern (regular expression) is matched, the callback process described below is kicked to the URL set as the destination for opening a push notification or a message in the application.
When HTML content is displayed in in-app messages, universal linking is also determined for requests that occur within that content.
For iOS apps, these matcher regular expressions can be added in the AppDelegate
or in the Apps designated .plist
file. For Android apps your class that extents Application
can be used or if that is not possible, the regular expressions can also be added to your AndroidManifest.xml
file.
// AppDelegate.m
#import <Repro/Repro.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Repro addOpenUrlFilterRegEx:@"https://example\\.com/page/"];
[Repro addOpenUrlFilterRegEx:@"your-domain\\.com/.+\?universal=true"];
...
}
// .plist file
/*
<dict>
<key>RPROpenUrlFilterRegExList</key>
<array>
<string>https://example\.com/page/</string>
<string>your-domain\.com/.+\?universal=true</string>
</array>
...
</dict>
*/
// MyApplication.java
import io.repro.android.Repro;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Repro.addOpenUrlFilterRegEx("https://example\\.com/page/");
Repro.addOpenUrlFilterRegEx("your-domain\\.com/.+\\?universal=true");
...
}
...
}
// AndroidManifest.xml
// To specify multiple URL patterns, enter them separated by commas.
<application>
...
<meta-data
android:name="io.repro.android.OpenUrlFilterRegExList"
android:value="https://example\\.com/page/;your-domain\\.com/.+\\?universal=true">
</meta-data>
</application>
// AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
Repro.add(openUrlFilterRegEx: "https://example\\.com/page/")
Repro.add(openUrlFilterRegEx: "your-domain\\.com/.+\\?universal=true")
...
}
// .plist file
/*
<dict>
<key>RPROpenUrlFilterRegExList</key>
<array>
<string>https://example\.com/page/</string>
<string>your-domain\.com/.+\?universal=true</string>
</array>
...
</dict>
*/
Please follow native iOS and Android instructions in order to add the filters
to the plist/AndroidManifest files or the main AppDelegate/Application classes.
Please follow native iOS and Android instructions in order to add the filters
to the plist/AndroidManifest files or the main AppDelegate/Application classes.
// YourAppNameScene.cpp
bool YourAppName::init() {
ReproCpp::addOpenUrlFilterRegEx("https://example\\.com/page/");
ReproCpp::addOpenUrlFilterRegEx("your-domain\\.com/.+\\?universal=true");
...
}
Please follow native iOS and Android instructions in order to add the filters
to the plist/AndroidManifest files or the main AppDelegate/Application classes.
Please follow native iOS and Android instructions in order to add the filters
to the plist/AndroidManifest files or the main AppDelegate/Application classes.
Warning
Specify the URL pattern to be set as a universal link as concretely as possible, including the domain and path , and should be all in lowercase .
If only a scheme is specified, such as https, a request made by a script executed in a screen displayed by an in-app message may be mistakenly judged as a universal link, and callback processing may be executed at an unintended timing.
If uppercase letters are used in the scheme/domain portion of the URL pattern, the scheme/domain portion is automatically converted to lowercase and processed when attempting to use a universal link to transition from a button displayed in an HTML in-app message. The pattern (regular expression) may not match and callback processing may not be executed at the intended timing.
Adding a callback handler for opening Universal-Links¶
Next a callback handler for custom processing of Universal-Links is added. The URL that was about to be opened is passed to the callback, where then depending on the URL custom code can be executed.
#import <Repro/Repro.h>
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Repro setOpenUrlCallback:^(NSURL *url) {
if ([url.host isEqualToString:@"example.com"]) {
// In case of your universal link perform navigation, present content, ...
handleUniversalLink(url);
}
}];
...
[Repro setup:@"YOUR_APP_TOKEN"];
...
}
// Set a callback that is executed everytime an URL is about to be opened
Repro.setOpenUrlCallback { url in
if url.host == "example.com" {
// In case of your universal link perform navigation, present content, ...
handleUniversalLink(url)
}
}
...
Repro.setup(token: "YOUR_APP_TOKEN")
...
import io.repro.android.Repro;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// In order to execute a callback when a push notification is tapped,
// the callback must be set in Application, not Activity.
Repro.setOpenUrlCallback(new Repro.OpenUrlCallback() {
// ** This callback method is executed in the main thread **
@Override
public void onOpened(Uri uri) {
if ("example.com".equals(uri.getHost())) {
// In case of your universal link perform navigation, present content, ...
}
}
});
...
Repro.setup(this, YOUR_APP_TOKEN);
...
}
...
}
Repro.setOpenUrlCallback((uri) { // uri is of type Uri
debugPrint("Universal Link Callback Handler received: " + uri.toString());
});
// Somewhere before Repro.Setup(...)
Repro.SetOpenUrlCallback(uri => // uri is of type Uri
{
Debug.Log("Universal Link Callback Handler received: " + uri.ToString());
});
bool YourAppName::init() {
ReproCpp::addOpenUrlFilterRegEx(...);
ReproCpp::setOpenUrlCallback([](const char *url) {
if (strcmp(url, "example.com") == 0) {
// In case of your universal link perform navigation, present content, ...
}
});
ReproCpp::setup("YOUR_APP_TOKEN")
...
}
Repro.setOpenUrlCallback(function(url) { // url is of type String
alert('Universal Link Callback Handler received: ' + url);
if (url.includes("http://example.org")) {
// In case of your universal link perform navigation, present content, ...
}
});
Repro.setOpenUrlCallback( (url) => { // url is of type String
console.log('Universal Link Callback Handler received: ' + url);
if (url.includes("http://example.org")) {
// In case of your universal link perform navigation, present content, ...
}
});