AddLocalNotification/ClearLocalNotifications
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.
The message structures for Android and iOS are different.
Supported Platform
- Unity
- Unreal Engine
Android, iOS
platform.Android, iOS
platform.Function Definition
- Unity
- Unreal Engine
// Add local push notification
void AddLocalNotification(string channel, GUALocalNotification localNotification);
// Remove local push notification
void ClearLocalNotifications(string channel);
// Add local push notification
static bool AddLocalNotification(const std::string channel, const GUALocalNotification &localNotification);
// Remove local push notification
static bool ClearLocalNotifications(const std::string &channel);
Input Parameters
- Unity
- Unreal Engine
Name | Parameter type | Description |
---|---|---|
channel | string | Channel definition For example: "Firebase", "XG" |
localNotification | GUALocalNotification | Local notification structure Different for Android and iOS |
Name | Parameter type | Description |
---|---|---|
channel | std::string | Channel definition For example: "Firebase", "XG" |
localNotification | GUALocalNotification | Local notification structure Different for Android and iOS |
Callback Processing
The callback processing API is GUAPushResultObserver. The callback data structure is GUAPushResult.
- Unity
- Unreal Engine
The callback event is PushNotificationEvents.
The callback methodID is GUA_PUSH_ADD_LOCAL_NOTIFICATION
,GUA_PUSH_CLEAR_LOCAL_NOTIFICATIONS
.
The callback event is OnReceiveNotification.
The callback methodID is kMethodIDPushAddLocalNotification
,kMethodIDPushClearLocalNotifications
.
Code Sample
- Unity
- Unreal Engine
#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
GUALocalNotification localNotification;
// TODO: Set localNotification
UnionAdapterAPI.GetPushService().AddLocalNotification("Firebase", localNotification);
UnionAdapterAPI.GetPushService().ClearLocalNotifications("Firebase");
Data Structures
Android
- Unity
- Unreal Engine
GUALocalNotification
Parameter | Type | Description |
---|---|---|
ActionType | int | Sets action type: 1: Opens activity or app 2: Opens browser 3: Opens Intent 4: Opens app through package name |
Lights | int | Whether to light up 0: No 1: Yes Default: 0 |
RingRaw | string | Specifies the in-app sound (raw/ring.mp3). Example: android.resource://intlgame.demo/raw/ring |
Vibrate | int | Whether to vibrate 0: No 1: Yes Default: 0 |
BuilderId | int | Specified notification ID Displayed notice with the same ID will be overwritten by a later fired notification |
Title | string | Sets the message title |
Content | string | Sets the message content |
TickerText | string | Sets the ticker text |
ActionParameter | string | When 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. |
FireTime | long | Sets the notification trigger time, long type (timestamp in UTC time, units: seconds) |
Ring | int | Whether to play sound 0: No 1: Yes Default: 1 |
SmallIcon | string | Specifies the small icon of the status bar (test.png). Example: test |
Type | int | [MSDK Only] Type |
IconType | int | [MSDK Only] Icon type |
StyleID | int | [MSDK Only] style ID |
CustomContent | string | [MSDK Only] Custom Content |
PackageDownloadUrl | string | [MSDK Only] Package download URL |
IconRes | string | [MSDK Only] Icon resolution |
Date | string | [MSDK Only] Date |
Hour | string | [MSDK Only] Hour |
Min | string | [MSDK Only] Minute |
GUALocalNotification
Parameter | Type | Description |
---|---|---|
action_type | int | Sets action type: 1: Opens activity or app 2: Opens browser 3: Opens Intent 4: Opens app through package name |
builderID | int64_t | Specified notification ID Displayed notice with the same ID will be overwritten by a later fired notification |
title | std::string | Sets the message title |
content | std::string | Sets the message content |
ticker_text | std::string | Sets the ticker text |
action_parameter | std::string | When 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. |
fire_time | int64_t | Sets the notification trigger time, long type (timestamp in UTC time, units: seconds) |
ring | int | Whether to play sound 0: No 1: Yes Default: 1 |
ring_raw | std::string | Specifies the in-app sound (raw/ring.mp3). Example: android.resource://intlgame.demo/raw/ring |
small_icon | std::string | Specifies the small icon of the status bar (test.png). Example: test |
lights | int | Whether to light up 0: No 1: Yes Default: 0 |
vibrate | int | Whether to vibrate 0: No 1: Yes Default: 0 |
type | int | [MSDK Only] type |
icon_type | int | [MSDK Only] Icon type |
styleID | int | [MSDK Only] Style ID |
custom_content | std::string | [MSDK Only] Custom content |
package_download_url | std::string | [MSDK Only] Package download URL |
icon_res | std::string | [MSDK Only] Icon resolution |
date | std::string | [MSDK Only] Date |
hour | std::string | [MSDK Only] Hour |
min | std::string | [MSDK Only] Minute |
iOS
- Unity
- Unreal Engine
GUALocalNotification
Parameter | Type | Description |
---|---|---|
RepeatType | int | Resending cycle 1: Minute 2: Hour 3: Day 4: Week 5: Month 6: Year Default: 0, indicating no resending |
FireTime | long | Local push trigger time |
Badge | int | Badge |
AlertBody | string | Push content |
AlertAction | string | Replaces popup button text. Default: Enabled |
UserInfo | Dictionary<string,string> | Custom parameter, which can be used to identify push notifications and add additional information |
AlertTitle | string | Short push description |
GUALocalNotification
Parameter | Type | Description |
---|---|---|
repeat_type | int | Resending cycle 1: Minute 2: Hour 3: Day 4: Week 5: Month 6: Year Default: 0, indicating no resending |
fire_time | int64_t | Local push trigger time |
badge | int | Badge |
alert_body | std::string | Push content |
alert_action | std::string | Replaces popup button text. Default: Enabled |
user_info | std::map<std::string, std::string> | Custom parameter, which can be used to identify push notifications and add additional information |
alert_title | std::string | Short push description |
notification_id | std::string | Specified push ID |