Skip to main content

Add or clear local notifications (AddLocalNotification/ClearLocalNotifications)

AndroidiOS
If you are using Unreal Engine, see AddLocalNotification in the Unreal Engine SDK.
caution

On the Android platform, you need to enable the ANDROID_LOCAL_NOTIFICATION_ENABLE setting in INTLConfig.ini.

Local notifications are set by the user, stored locally, and triggered by time.

If the set time is less than the current device time, the notification will pop up immediately.

info

Android and iOS message structures are different.

Function definition

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

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

Parameter description

ParametersTypeExplanation
channelstringChannel definition
For example "Firebase"
localNotificationINTLLocalNotificationLocal message structure

Observers

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

Callback ID is INTL_PUSH_ADD_LOCAL_NOTIFICATION, INTL_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 nameTypeExplanation
ActionTypeintSet action type:
1: Open activity or app itself
2: Open browser
3: Open Intent
4: Open app by package name
NotificationIDintSpecify notification ID; notifications with the same ID that are already displayed will be overwritten by later-triggered notifications.
TitleStringSet message title
ContentStringSet message content
TickerTextStringSet marquee text in title bar
ActionParameterStringWhen ActionType=1, ActionParameter could be the class name of an Activity in the application.For example com.intl.TestActivity.
When ActionType=2, ActionParameter is a URL, and clicking the notification will directly open the URL in a browser.
When ActionType=3, ActionParameter is a serialized Intent.
When ActionType=4, ActionParameter is the application package name.
FireTimelongSet notification trigger time, long type (UTC time timestamp, unit: seconds)
SoundEnabledintPlay sound
0: No, 1: Yes
Default: 1
RingUriStringSpecify in-app sound (raw/ring.mp3), e.g., android.resource://intlgame.demo/raw/ring
SmallIconStringSpecify small image in status bar (test.png)
e.g., test
LightsintBreathing light
0: No, 1: Yes
Default: 0
VibrateintVibration
0: No, 1: Yes
Default: 0

iOS

INTLLocalNotification

Member variableTypeExplanation
NotificationIDString[Required]
Specify notification ID
Notifications with the same ID already displayed will be overwritten by later-triggered notifications.
RepeatTypeintPush repeat cycle
1: Minutes
2: Hours
3: Days
4: Weeks
5: Months
6: Years
Default: 0, meaning no repetition
FireTimelongLocal notification trigger time
BadgeintBadge
AlertBodyStringPush content
AlertActionStringReplace button text content in dialog box
Default: Launch
UserInfoList<Dictionary<string,string>>Custom parameters for identifying push and adding additional information
AlertTitleStringBrief description of the push