本地推送我是这样写的:
LocalNotification localNotification = new LocalNotification(); localNotification.fireDate = newDate; localNotification.alertBody = message; localNotification.applicationIconBadgeNumber = 1; localNotification.hasAction = true; localNotification.alertAction = "SlotGame1"; if (isRepeatDay){ localNotification.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.ISO8601Calendar; localNotification.repeatInterval = UnityEngine.iOS.CalendarUnit.Day; } localNotification.soundName = LocalNotification.defaultSoundName; NotificationServices.ScheduleLocalNotification(localNotification);然后是得到推送后点进去再退出来的时候,发现图标上的Badge数量还是依然存在:开始是按照雨松大神的写的:
LocalNotification l = new LocalNotification(); l.applicationIconBadgeNumber = -1; NotificationServices.PResentLocalNotificationNow(l); NotificationServices.CancelAllLocalNotifications(); NotificationServices.ClearLocalNotifications();完了之后并没有效果,BadgeNumber还是存在,后面在网上找到另一人写的方法,只需要将上面的代码添加一句话LocalNotification l = new LocalNotification(); l.applicationIconBadgeNumber = -1; l.hasAction = false; NotificationServices.PresentLocalNotificationNow(l); NotificationServices.CancelAllLocalNotifications(); NotificationServices.ClearLocalNotifications();主要是添加了hasAction,但是我在实际测试的时候,偶尔还是会出现不消失的问题多次试了之后发现就是有一定延迟,于是在原来的基础上加上一个协程,在PresentLocalNotificationNow之后等一段时间再clear和cancel
IEnumerator CleanNotification(){ #if UNITY_ipHONE LocalNotification l = new LocalNotification(); l.applicationIconBadgeNumber = -1; l.hasAction = false; NotificationServices.PresentLocalNotificationNow(l); yield return new WaitForSeconds(0.2f); NotificationServices.CancelAllLocalNotifications(); NotificationServices.ClearLocalNotifications(); #endif }
新闻热点
疑难解答