本地推送我是這樣寫的:
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 }
新聞熱點
疑難解答