AddLocalNotification/ClearLocalNotifications
AndroidiOS
If you were looking for the method for use with Unreal Engine, see AddLocalNotification for Unreal Engine SDK.
If you were looking for the method for use with Unreal Engine, see AddLocalNotification for Unreal Engine SDK.
caution
For Android devices, it is mandatory to configure ANDROID_LOCAL_NOTIFICATION_ENABLE
in INTLConfig.ini.
Local notifications are customized by users, saved locally, and triggered by time.
When the time set is earlier than the current time, the notification will be displayed immediately.
info
The message structures of Android and iOS are different.
Function definition
// Add local push notifications
public static void AddLocalNotification(string channel, INTLLocalNotification localNotification);
// Clear local push notifications
public static void ClearLocalNotifications(string channel);
Input parameters
Parameter | Type | Description |
---|---|---|
channel | string | Channel definition For example: "Firebase" |
localNotification | INTLLocalNotification | Local notification body |
Observers
The callback processing interface is PushResultObserver. The callback data structure is PushResult.
The callback methodID 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 | Description |
---|---|---|
ActionType | int | Set action type 1: Open activity or app 2: Open browser 3: Open Intent 4: Open app through package name |
NotificationID | int | Specifies the notification ID; when a notification with the same ID has already been displayed, the older notification is overwritten |
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 the in-app activity.For 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) |
SoundEnabled | int | Whether to play sound 0: No 1: Yes Default: 1 |
RingUri | string | Specifies the in-app sound (raw/ring.mp3), for example: android.resource://intlgame.demo/raw/ring |
SmallIcon | string | Specifies the small status bar icon (test.png) For 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 |
iOS
INTLLocalNotification
Member Variable | Type | Description |
---|---|---|
NotificationID | string | [Required] Specifies the notification ID. When a notification with the same ID has already been displayed, the older notification is overwritten. |
RepeatType | int | Push resend cycle 1: minutes 2: hours 3: days 4: weeks 5: months 6: years Default: 0, indicates no resending |
FireTime | long | Local push trigger time |
Badge | int | Badge |
AlertBody | string | Push content |
AlertAction | string | Replace popup button text Default: Enabled |
UserInfo | List<Dictionary<string,string>> | Custom parameter, can be used to identify push notifications and add additional information |
AlertTitle | string | Short push description |