本地推送我是這樣寫的:
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);然后是得到推送后點(diǎn)進(jìn)去再退出來(lái)的時(shí)候,發(fā)現(xiàn)圖標(biāo)上的Badge數(shù)量還是依然存在:開始是按照雨松大神的寫的:
LocalNotification l = new LocalNotification(); l.applicationIconBadgeNumber = -1; NotificationServices.PResentLocalNotificationNow(l); NotificationServices.CancelAllLocalNotifications(); NotificationServices.ClearLocalNotifications();完了之后并沒(méi)有效果,BadgeNumber還是存在,后面在網(wǎng)上找到另一人寫的方法,只需要將上面的代碼添加一句話LocalNotification l = new LocalNotification(); l.applicationIconBadgeNumber = -1; l.hasAction = false; NotificationServices.PresentLocalNotificationNow(l); NotificationServices.CancelAllLocalNotifications(); NotificationServices.ClearLocalNotifications();主要是添加了hasAction,但是我在實(shí)際測(cè)試的時(shí)候,偶爾還是會(huì)出現(xiàn)不消失的問(wèn)題多次試了之后發(fā)現(xiàn)就是有一定延遲,于是在原來(lái)的基礎(chǔ)上加上一個(gè)協(xié)程,在PresentLocalNotificationNow之后等一段時(shí)間再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 }
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注