Add or clear local notifications (AddLocalNotification/ClearLocalNotifications)
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
| Parameters | Type | Explanation |
|---|---|---|
| channel | string | Channel definition For example "Firebase" |
| localNotification | INTLLocalNotification | Local 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 name | Type | Explanation |
|---|---|---|
| ActionType | int | Set action type: 1: Open activity or app itself 2: Open browser 3: Open Intent 4: Open app by package name |
| NotificationID | int | Specify notification ID; notifications with the same ID that are already displayed will be overwritten by later-triggered notifications. |
| Title | String | Set message title |
| Content | String | Set message content |
| TickerText | String | Set marquee text in title bar |
| ActionParameter | String | When 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. |
| FireTime | long | Set notification trigger time, long type (UTC time timestamp, unit: seconds) |
| SoundEnabled | int | Play sound 0: No, 1: Yes Default: 1 |
| RingUri | String | Specify in-app sound (raw/ring.mp3), e.g., android.resource://intlgame.demo/raw/ring |
| SmallIcon | String | Specify small image in status bar (test.png) e.g., test |
| Lights | int | Breathing light 0: No, 1: Yes Default: 0 |
| Vibrate | int | Vibration 0: No, 1: Yes Default: 0 |
iOS
INTLLocalNotification
| Member variable | Type | Explanation |
|---|---|---|
| NotificationID | String | [Required] Specify notification ID Notifications with the same ID already displayed will be overwritten by later-triggered notifications. |
| RepeatType | int | Push repeat cycle 1: Minutes 2: Hours 3: Days 4: Weeks 5: Months 6: Years Default: 0, meaning no repetition |
| FireTime | long | Local notification trigger time |
| Badge | int | Badge |
| AlertBody | String | Push content |
| AlertAction | String | Replace button text content in dialog box Default: Launch |
| UserInfo | List<Dictionary<string,string>> | Custom parameters for identifying push and adding additional information |
| AlertTitle | String | Brief description of the push |