Skip to main content

AddLocalNotification/ClearLocalNotifications

caution

For an Android device, users must configure ANDROID_LOCAL_NOTIFICATION_ENABLE in INTLConfig.ini.

[Player Network SDK & MSDK] Local notifications are customized by users, saved locally, and triggered by time.

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

info

The message structures for Android and iOS are different.

Supported Platform

Supports Android, iOS platform.

Function Definition

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

// Remove local push notification
void ClearLocalNotifications(string channel);

Input Parameters

NameParameter typeDescription
channelstringChannel definition
For example: "Firebase", "XG"
localNotificationGUALocalNotificationLocal notification structure
Different for Android and iOS

Callback Processing

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

The callback event is PushNotificationEvents. The callback methodID is GUA_PUSH_ADD_LOCAL_NOTIFICATIONGUA_PUSH_CLEAR_LOCAL_NOTIFICATIONS.

Code Sample

#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 Structures

Android

GUALocalNotification

ParameterTypeDescription
ActionTypeintSets action type:
1: Opens activity or app
2: Opens browser
3: Opens Intent
4: Opens app through package name
LightsintWhether to light up
0: No
1: Yes
Default: 0
RingRawstringSpecifies the in-app sound (raw/ring.mp3).
Example: android.resource://intlgame.demo/raw/ring
VibrateintWhether to vibrate
0: No
1: Yes
Default: 0
BuilderIdintSpecified notification ID
Displayed notice with the same ID will be overwritten by a later fired notification
TitlestringSets the message title
ContentstringSets the message content
TickerTextstringSets the ticker text
ActionParameterstringWhen ActionType=1, ActionParameter can be the class name of the in-app activity.
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)
RingintWhether to play sound
0: No
1: Yes
Default: 1
SmallIconstringSpecifies the small icon of the status bar (test.png).
Example: test
Typeint[MSDK Only] Type
IconTypeint[MSDK Only] Icon type
StyleIDint[MSDK Only] style ID
CustomContentstring[MSDK Only] Custom Content
PackageDownloadUrlstring[MSDK Only] Package download URL
IconResstring[MSDK Only] Icon resolution
Datestring[MSDK Only] Date
Hourstring[MSDK Only] Hour
Minstring[MSDK Only] Minute

iOS

GUALocalNotification

ParameterTypeDescription
RepeatTypeintResending cycle
1: Minute
2: Hour
3: Day
4: Week
5: Month
6: Year
Default: 0, indicating no resending
FireTimelongLocal push trigger time
BadgeintBadge
AlertBodystringPush content
AlertActionstringReplaces popup button text.
Default: Enabled
UserInfoDictionary<string,string> Custom parameter, which can be used to identify push notifications and add additional information
AlertTitlestringShort push description