Skip to main content

Add or clear local notifications (AddLocalNotification/ClearLocalNotifications)

caution

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

[Player Network SDK & MSDK] Local notifications are customized by the user, stored locally, and triggered according to time.

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

info

The message structures differ between Android and iOS.

Supported platforms

Supports Android, iOS platform.

Function Definition

// Add local push notifications
void AddLocalNotification(string channel, GUALocalNotification localNotification);

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

Input Parameters

NameParameter TypeDescription
channelstringThird-party channel proprietary terms
For example: "XG", "Firebase"
localNotificationGUALocalNotificationLocal notification structure
Different for Android and iOS

Callback Handling

The callback processing interface is GUAPushResultObserver.The callback data structure is GUAPushResult.

The callback event is PushNotificationEvents. The callback IDs are GUA_PUSH_ADD_LOCAL_NOTIFICATION and GUA_PUSH_CLEAR_LOCAL_NOTIFICATIONS.

Code Example

#if UNITY_IOS
GUALocalNotification localNotification = new GUALocalNotification ();
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
localNotification.RepeatType = 1;
localNotification.FireTime = Convert.Toint(ts.TotalSeconds) + 5;
localNotification.Badge = 2;
localNotification.AlertBody = "INTL Push iOS Test";
localNotification.AlertAction = "INTL Action";
Dictionary<string,string> userInfo = new Dictionary<string,string>();
userInfo["key1"] = "value1";
userInfo["key2"] = "value2";
localNotification.UserInfo = userInfo;
localNotification.AlertTitle = "title";
GUA_NAMESPACE::GUAPushService::AddLocalNotification("Firebase", localNotification);

GUA_NAMESPACE::GUAPushService::ClearLocalNotifications("Firebase");
#endif
#if UNITY_ANDROID
GUALocalNotification localNotification = new GUALocalNotification();
localNotification.ActionType = 1;
localNotification.Lights = 1;
localNotification.Ring = 1;
localNotification.Vibrate = 1;
localNotification.BuilderId = 0;
localNotification.Content = "INTL Push Android content";
localNotification.ActionParameter = "com.intlgame.demo.xxxActivity";
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
localNotification.FireTime = Convert.Toint(ts.TotalSeconds) + 5;
localNotification.Title = "INTL Push Android title";
localNotification.TickerText = "INTL Push Android ticker text";
localNotification.RingRaw = "android.resource://intlgame.demo/raw/ring_file";
localNotification.SmallIcon = "drawable_name";

//default
localNotification.Type = -1;
localNotification.IconType = -1;
localNotification.StyleId = -1;
localNotification.CustomContent = "";
localNotification.PackageDownloadUrl = "";
localNotification.IconRes = "";
localNotification.Date = "";
localNotification.Hour = "";
localNotification.Min = "";
GUA_NAMESPACE::GUAPushService::AddLocalNotification("Firebase", localNotification);

GUA_NAMESPACE::GUAPushService::ClearLocalNotifications("Firebase");
#endif

Data structure

Android

GUALocalNotification

ParametersTypeDescription
ActionTypeintSet Action Type:
1: Open the activity or the app itself
2: Open the browser
3: Open an Intent
4: Open an app via its package name
LightsintEnable breathing light
0: No, 1: Yes
Default: 0
RingRawstringSpecify in-app sound (raw/ring.mp3)
For example: android.resource://intlgame.demo/raw/ring
VibrateintEnable vibration
0: No, 1: Yes
Default: 0
BuilderIdintSpecify Notification ID
Notifications with the same ID that have already been displayed will be overwritten by later notifications
TitlestringSet message title
ContentstringSet message content
TickerTextstringSet ticker text content
ActionParameterstringWhen ActionType=1, ActionParameter can be the class name of an Activity within the app.
For example com.intl.TestActivity.
When ActionType=2, ActionParameter is a URL that will be opened directly in the browser upon notification click.
When ActionType=3, ActionParameter is a serialized Intent.
When ActionType=4, ActionParameter is the application's package name.
FireTimelongSet the notification trigger time, of type long (UTC timestamp in seconds)
RingintEnable sound playback
0: No, 1: Yes
Default: 1
SmallIconstringSpecify the small icon for the status bar (test.png)
e.g.: test
Typeint[MSD only] Type
IconTypeint[MSD only] Icon type
StyleIDint[MSD only] style ID
CustomContentstring[MSD only] Custom Content
PackageDownloadUrlstring[MSD only] Package download URL
IconResstring[MSD only] Icon resolution
Datestring[MSD only] Date
Hourstring[MSD only] Hour
Minstring[MSD only] Minute

iOS

GUALocalNotification

ParametersTypeDescription
RepeatTypeintPush repeat interval
1: Minute
2: Hour
3: Day
4: Week
5: Month
6: Year
Default: 0, meaning no repeat
FireTimelongTime to trigger the local notification
BadgeintBadge
AlertBodystringContent of the push
AlertActionstringReplace the button text in the popup
Default: Launch
UserInfoDictionary<string,string>Custom parameters, which can be used to identify push notifications and add additional information
AlertTitlestringShort description of the push