|
(1)导入插件
using Unity.Notifications.iOS; 否则请前往Unity Asset Store下载相关插件
(2)注销所有通知
iOSNotificationCenter.ApplicationBadge = 0;
iOSNotificationCenter.RemoveAllDeliveredNotifications();
iOSNotificationCenter.RemoveAllScheduledNotifications(); (3)设置每日10点发送一条通知
先创建一个触发器,如下:var calendarTrigger = new iOSNotificationCalendarTrigger() { Hour = 10, Minute = 0, Second = 0, Repeats = true }; 然后创建通知对象iOSNotification notification = new iOSNotification(){
Data = data,
Title = title, //标题
Body = msg, //消息内容
Identifier = "Notification_" + notificationId, //每条通知的id注意做区分
Badge = notificationId,
ShowInForeground = true, //应用在前台是否还显示通知
ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound | PresentationOption.Badge), //通知紧急程度
CategoryIdentifier = "category_a",
ThreadIdentifier = "thread1",
Trigger = calendarTrigger, //触发器
}; (4)注册通知
iOSNotificationCenter.ScheduleNotification(notification); |
|