Add or clear local notifications (AddLocalNotification/ClearLocalNotifications)
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.
The message structures differ between Android and iOS.
Supported platforms
- Unity
- Unreal Engine
Android, iOS platform.Android, iOS platform.Function Definition
- Unity
- Unreal Engine
// Add local push notifications
void AddLocalNotification(string channel, GUALocalNotification localNotification);
// Clear local push notifications
void ClearLocalNotifications(string channel);
// Add local push notifications
static bool AddLocalNotification(const std::string channel, const GUALocalNotification &localNotification);
// Clear local push notifications
static bool ClearLocalNotifications(const std::string &channel);
Input Parameters
- Unity
- Unreal Engine
| Name | Parameter Type | Description |
|---|---|---|
| channel | string | Third-party channel proprietary terms For example: "XG", "Firebase" |
| localNotification | GUALocalNotification | Local notification structure Different for Android and iOS |
| Name | Parameter Type | Description |
|---|---|---|
| channel | std::string | Third-party channel proprietary terms For example: "XG", "Firebase" |
| localNotification | GUALocalNotification | Local notification structure Different for Android and iOS |
Callback Handling
The callback processing interface is GUAPushResultObserver.The callback data structure is GUAPushResult.
- Unity
- Unreal Engine
The callback event is PushNotificationEvents. The callback IDs are GUA_PUSH_ADD_LOCAL_NOTIFICATION and GUA_PUSH_CLEAR_LOCAL_NOTIFICATIONS.
The callback event is OnReceiveNotification. The callback IDs are kMethodIDPushAddLocalNotification and kMethodIDPushClearLocalNotifications.
Code Example
- 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 structure
Android
- Unity
- Unreal Engine
GUALocalNotification
| Parameters | Type | Description |
|---|---|---|
| ActionType | int | Set 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 |
| Lights | int | Enable breathing light 0: No, 1: Yes Default: 0 |
| RingRaw | string | Specify in-app sound (raw/ring.mp3) For example: android.resource://intlgame.demo/raw/ring |
| Vibrate | int | Enable vibration 0: No, 1: Yes Default: 0 |
| BuilderId | int | Specify Notification ID Notifications with the same ID that have already been displayed will be overwritten by later notifications |
| Title | string | Set message title |
| Content | string | Set message content |
| TickerText | string | Set ticker text content |
| ActionParameter | string | When 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. |
| FireTime | long | Set the notification trigger time, of type long (UTC timestamp in seconds) |
| Ring | int | Enable sound playback 0: No, 1: Yes Default: 1 |
| SmallIcon | string | Specify the small icon for the status bar (test.png) e.g.: test |
| Type | int | [MSD only] Type |
| IconType | int | [MSD only] Icon type |
| StyleID | int | [MSD only] style ID |
| CustomContent | string | [MSD only] Custom Content |
| PackageDownloadUrl | string | [MSD only] Package download URL |
| IconRes | string | [MSD only] Icon resolution |
| Date | string | [MSD only] Date |
| Hour | string | [MSD only] Hour |
| Min | string | [MSD only] Minute |
GUALocalNotification
| Parameters | Type | Description |
|---|---|---|
| action_type | int | Set 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 |
| builderID | int64_t | Specify Notification ID Notifications with the same ID that have already been displayed will be overwritten by later notifications |
| title | std::string | Set message title |
| content | std::string | Set message content |
| ticker_text | std::string | Set ticker text content |
| action_parameter | std::string | When 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. |
| fire_time | int64_t | Set the notification trigger time, of type long (UTC timestamp in seconds) |
| ring | int | Enable sound playback 0: No, 1: Yes Default: 1 |
| ring_raw | std::string | Specify in-app sound (raw/ring.mp3) For example: android.resource://intlgame.demo/raw/ring |
| small_icon | std::string | Specify the small icon for the status bar (test.png) e.g.: test |
| lights | int | Enable breathing light 0: No, 1: Yes Default: 0 |
| vibrate | int | Enable vibration 0: No, 1: Yes Default: 0 |
| type | int | [MSD only] type |
| icon_type | int | [MSD only] Icon type |
| styleID | int | [MSD only] Style ID |
| custom_content | std::string | [MSD only] Custom content |
| package_download_url | std::string | [MSD only] Package download URL |
| icon_res | std::string | [MSD only] Icon resolution |
| date | std::string | [MSD only] Date |
| hour | std::string | [MSD only] Hour |
| min | std::string | [MSD only] Minute |
iOS
- Unity
- Unreal Engine
GUALocalNotification
| Parameters | Type | Description |
|---|---|---|
| RepeatType | int | Push repeat interval 1: Minute 2: Hour 3: Day 4: Week 5: Month 6: Year Default: 0, meaning no repeat |
| FireTime | long | Time to trigger the local notification |
| Badge | int | Badge |
| AlertBody | string | Content of the push |
| AlertAction | string | Replace the button text in the popup Default: Launch |
| UserInfo | Dictionary<string,string> | Custom parameters, which can be used to identify push notifications and add additional information |
| AlertTitle | string | Short description of the push |
GUALocalNotification
| Parameters | Type | Description |
|---|---|---|
| repeat_type | int | Push repeat interval 1: Minute 2: Hour 3: Day 4: Week 5: Month 6: Year Default: 0, meaning no repeat |
| fire_time | int64_t | Time to trigger the local notification |
| badge | int | Badge |
| alert_body | std::string | Content of the push |
| alert_action | std::string | Replace the button text in the popup Default: Launch |
| user_info | std::map<std::string, std::string> | Custom parameters, which can be used to identify push notifications and add additional information |
| alert_title | std::string | Short description of the push |
| notification_id | std::string | Specify notification id |