增加或清空本地推送(AddLocalNotification/ClearLocalNotifications)
警告
Android 平台需启用 INTLConfig.ini 里的 ANDROID_LOCAL_NOTIFICATION_ENABLE 配置。
[Player Network SDK & MSDK] 本地通知由用户自定义设置,保存在本地,根据时间触发。
当设置的时间小于当前设备时间,通知立即弹出。
说明
Android 和 iOS 的消息结构体不一样。
支持的平台
- Unity
- Unreal Engine
支持
Android, iOS 平台。支持
Android, iOS 平台。函数定义
- Unity
- Unreal Engine
// 增加本地推送
void AddLocalNotification(string channel, GUALocalNotification localNotification);
// 清空本地推送
void ClearLocalNotifications(string channel);
// 增加本地推送
static bool AddLocalNotification(const std::string channel, const GUALocalNotification &localNotification);
// 清空本地推送
static bool ClearLocalNotifications(const std::string &channel);
入参说明
- Unity
- Unreal Engine
| 名称 | 参数类型 | 说明 |
|---|---|---|
| channel | string | 三方渠道专有名词 比如 "XG", "Firebase" |
| localNotification | GUALocalNotification | 本地通知结构体 Android 和 iOS 不同 |
| 名称 | 参数类型 | 说明 |
|---|---|---|
| channel | std::string | 三方渠道专有名词 比如 "XG", "Firebase" |
| localNotification | GUALocalNotification | 本地通知结构体 Android 和 iOS 不同 |
回调处理
回调处理接口是 GUAPushResultObserver。回调数据结构是 GUAPushResult。
- Unity
- Unreal Engine
回调事件是 PushNotificationEvents。 回调 ID 是 GUA_PUSH_ADD_LOCAL_NOTIFICATION,GUA_PUSH_CLEAR_LOCAL_NOTIFICATIONS。
回调事件是 OnReceiveNotification。 回调 ID 是 kMethodIDPushAddLocalNotification,kMethodIDPushClearLocalNotifications。
代码示例
- 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 测试";
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");
数据结构
Android
- Unity
- Unreal Engine
GUALocalNotification
| 参数 | 类型 | 说明 |
|---|---|---|
| ActionType | int | 设置动作类型: 1:打开 activity 或 app 本身 2:打开浏览器 3:打开Intent 4:通过包名打开应用 |
| Lights | int | 是否呼吸灯 0:否,1:是 默认:0 |
| RingRaw | string | 指定应用内的声音(raw/ring.mp3) 例如:android.resource://intlgame.demo/raw/ring |
| Vibrate | int | 是否振动 0:否,1:是 默认:0 |
| BuilderId | int | 指定通知 id 已展示的相同 id 的通知会被后触发的通知覆盖 |
| Title | string | 设置消息标题 |
| Content | string | 设置消息内容 |
| TickerText | string | 设置标题栏走马灯内容 |
| ActionParameter | string | 当 ActionType=1 时,ActionParameter 可以为应用内的 Activity 的类名。 例如 com.intl.TestActivity。 当 ActionType=2 时,ActionParameter 是一个 URL,点击通知后,直接用浏览器打开此URL地址。 当 ActionType=3 时,ActionParameter 是一个序列化的 Intent。 当 ActionType=4 时,ActionParameter 为应用包名。 |
| FireTime | long | 设置通知触发时间,long 类型(UTC时间的时间戳,单位:秒) |
| Ring | int | 是否播放声音 0:否,1:是 默认:1 |
| SmallIcon | string | 指定状态栏的小图片(test.png) 例如:test |
| Type | int | [仅限 MSD] Type |
| IconType | int | [仅限 MSD] Icon type |
| StyleID | int | [仅限 MSD] style ID |
| CustomContent | string | [仅限 MSD] Custom Content |
| PackageDownloadUrl | string | [仅限 MSD] Package download URL |
| IconRes | string | [仅限 MSD] Icon resolution |
| Date | string | [仅限 MSD] Date |
| Hour | string | [仅限 MSD] Hour |
| Min | string | [仅限 MSD] Minute |
GUALocalNotification
| 参数 | 类型 | 说明 |
|---|---|---|
| action_type | int | 设置动作类型: 1:打开 activity 或 app 本身 2:打开浏览器 3:打开Intent 4:通过包名打开应用 |
| builderID | int64_t | 指定通知 id 已展示的相同 id 的通知会被后触发的通知覆盖 |
| title | std::string | 设置消息标题 |
| content | std::string | 设置消息内容 |
| ticker_text | std::string | 设置标题栏走马灯内容 |
| action_parameter | std::string | 当 ActionType=1 时,ActionParameter 可以为应用内的 Activity 的类名。 例如 com.intl.TestActivity。 当 ActionType=2 时,ActionParameter 是一个 URL,点击通知后,直接用浏览器打开此URL地址。 当 ActionType=3 时,ActionParameter 是一个序列化的 Intent。 当 ActionType=4 时,ActionParameter 为应用包名。 |
| fire_time | int64_t | 设置通知触发时间,long 类型(UTC时间的时间戳,单位:秒) |
| ring | int | 是否播放声音 0:否,1:是 默认:1 |
| ring_raw | std::string | 指定应用内的声音(raw/ring.mp3) 例如:android.resource://intlgame.demo/raw/ring |
| small_icon | std::string | 指定状态栏的小图片(test.png) 例如:test |
| lights | int | 是否呼吸灯 0:否,1:是 默认 :0 |
| vibrate | int | 是否振动 0:否,1:是 默认:0 |
| type | int | [仅限 MSD] type |
| icon_type | int | [仅限 MSD] Icon type |
| styleID | int | [仅限 MSD] Style ID |
| custom_content | std::string | [仅限 MSD] Custom content |
| package_download_url | std::string | [仅限 MSD] Package download URL |
| icon_res | std::string | [仅限 MSD] Icon resolution |
| date | std::string | [仅限 MSD] Date |
| hour | std::string | [仅限 MSD] Hour |
| min | std::string | [仅限 MSD] Minute |
iOS
- Unity
- Unreal Engine
GUALocalNotification
| 参数 | 类型 | 说明 |
|---|---|---|
| RepeatType | int | 推送重复发送周期 1:分钟 2:小时 3:天 4:星期 5:月 6:年 默认:0,代表不重复 |
| FireTime | long | 本地推送触发的时间 |
| Badge | int | 角标 |
| AlertBody | string | 推送的内容 |
| AlertAction | string | 替换弹框的按钮文字内容 默认为:启动 |
| UserInfo | Dictionary<string,string> | 自定义参数,可以用来标识推送和增加附加信息 |
| AlertTitle | string | 推送的简短描述 |
GUALocalNotification
| 参数 | 类型 | 说明 |
|---|---|---|
| repeat_type | int | 推送重复发送周期 1:分钟 2:小时 3:天 4:星期 5:月 6:年 默认:0,代表不重复 |
| fire_time | int64_t | 本地推送触发的时间 |
| badge | int | 角标 |
| alert_body | std::string | 推送的内容 |
| alert_action | std::string | 替换弹框的按钮文字内容 默认为:启动 |
| user_info | std::map<std::string, std::string> | 自定义参数,可以用来标识推送和增加附加信息 |
| alert_title | std::string | 推送的简短描述 |
| notification_id | std::string | 指定通知 id |