Skip to main content

AddLocalNotification/ClearLocalNotifications

AndroidiOS
If you were looking for the method for use with Unreal Engine, see AddLocalNotification for Unreal Engine SDK.
caution

For Android devices, it is mandatory to configure ANDROID_LOCAL_NOTIFICATION_ENABLE in INTLConfig.ini.

Local notifications are customized by users, saved locally, and triggered by time.

When the time set is earlier than the current time, the notification will be displayed immediately.

info

The message structures of Android and iOS are different.

Function definition

// Add local push notifications
public static void AddLocalNotification(string channel, INTLLocalNotification localNotification);

// Clear local push notifications
public static void ClearLocalNotifications(string channel);

Input parameters

ParameterTypeDescription
channelstringChannel definition
For example: "Firebase"
localNotificationINTLLocalNotificationLocal notification body

Observers

The callback processing interface is PushResultObserver. The callback data structure is PushResult.

The callback methodID is INTL_PUSH_ADD_LOCAL_NOTIFICATIONINTL_PUSH_CLEAR_LOCAL_NOTIFICATIONS.

Code sample

#if UNITY_IOS
INTLLocalNotification message = new INTLLocalNotification ();
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
message.FireTime = Convert.Toint(ts.TotalSeconds) + 5;
message.AlertBody = "INTL Push iOS test";
message.AlertAction = "INTL Action";
message.Badge = 2;
message.RepeatType = 1;
Dictionary<string,string> userInfo1 = new Dictionary<string,string>();
userInfo1["key1"] = "value1";
Dictionary<string,string> userInfo2 = new Dictionary<string,string>();
userInfo2["key2"] = "value2";
message.UserInfo = new List<Dictionary<string,string>>();
message.UserInfo.Add(userInfo1);
message.UserInfo.Add(userInfo2);
INTLAPI.AddLocalNotification (INTLChannel.Firebase, message);
//INTLAPI.ClearLocalNotifications(INTLChannel.Firebase);
#endif
#if UNITY_ANDROID
INTLLocalNotification message = new INTLLocalNotification();
message.NotificationID = 0;//
message.ActionType = 1;
message.SoundEnabled = 1;
message.Lights = 1;
message.Vibrate = 1;
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
message.FireTime = Convert.Toint(ts.TotalSeconds) + 5;
message.Title = "INTL Push Android title";
message.Content = "INTL Push Android content";
message.TickerText = "INTL Push Android ticker text";
message.ActionParameter = "com.intlgame.demo.xxxActivity";
message.RingUri = "android.resource://intlgame.demo/raw/ring_file";
message.SmallIcon = "drawable_name";
INTLAPI.AddLocalNotification (INTLChannel.xxx, message);
//INTLAPI.ClearLocalNotifications(INTLChannel.xxx);
#endif

Data structure

Android

INTLLocalNotification

Member Variable NameTypeDescription
ActionTypeintSet action type
1: Open activity or app
2: Open browser
3: Open Intent
4: Open app through package name
NotificationIDintSpecifies the notification ID; when a notification with the same ID has already been displayed, the older notification is overwritten
TitlestringSet message title
ContentstringSet message content
TickerTextstringSet ticker text content
ActionParameterstringWhen ActionType=1, ActionParameter can be the class name of the in-app activity.For example: com.intl.TestActivity.
When ActionType=2, ActionParameter is a URL. When the user clicks the notification, this URL is directly opened in the browser.
When ActionType=3, ActionParameter is a serial Intent.
When ActionType=4, ActionParameter is the app package name.
FireTimelongSets the notification trigger time, long type (timestamp in UTC time, units: seconds)
SoundEnabledintWhether to play sound
0: No
1: Yes
Default: 1
RingUristringSpecifies the in-app sound (raw/ring.mp3), for example: android.resource://intlgame.demo/raw/ring
SmallIconstringSpecifies the small status bar icon (test.png)
For example: test
LightsintWhether to light up
0: No
1: Yes
Default: 0
VibrateintWhether to vibrate
0: No
1: Yes
Default: 0

iOS

INTLLocalNotification

Member VariableTypeDescription
NotificationIDstring[Required]
Specifies the notification ID.
When a notification with the same ID has already been displayed, the older notification is overwritten.
RepeatTypeintPush resend cycle
1: minutes
2: hours
3: days
4: weeks
5: months
6: years
Default: 0, indicates no resending
FireTimelongLocal push trigger time
BadgeintBadge
AlertBodystringPush content
AlertActionstringReplace popup button text
Default: Enabled
UserInfoList<Dictionary<string,string>> Custom parameter, can be used to identify push notifications and add additional information
AlertTitlestringShort push description