Удалить «локальные или удаленные уведомления» из центра уведомлений - PullRequest
0 голосов
/ 30 января 2019

Мне нужно очистить все уведомления из моего центра уведомлений. Я пытался cancellAllLocalNotification и UIApplication.shared.applicationIconBadgeNumber = 0, но он не работает. Я использую swift 4 и xcode 10.1 и ios 12. Никто не может мне помочь ..

Ответы [ 2 ]

0 голосов
/ 30 января 2019
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
        print("payload",payload.dictionaryPayload)
{
 let state = UIApplication.shared.applicationState
        if state == .background  || state == .inactive{
         startTimer()
}
}

func startTimer() {

        timer2 = Timer.scheduledTimer(timeInterval: 7, target: self, selector: (#selector(updateTimer2)), userInfo: nil, repeats: true)
 }
@objc func updateTimer2() {

        seconds2 += 7
        isPushNotificationCallReceived = true
        let content = UNMutableNotificationContent()
        content.title = self.message
        content.body = self.callerName
        content.badge = 0
        content.sound = UNNotificationSound(named: "phone_loud.wav")
        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false)
        let request = UNNotificationRequest(identifier: "SimplifiedIOSNotification", content: content, trigger: trigger)
        UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)]
        print(seconds2)

        if seconds2 == 28 {

            isPushNotificationCallReceived = false
            seconds2 = 0
            timer2.invalidate()

 UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers:
 ["SimplifiedIOSNotification"])
 UIApplication.shared.applicationIconBadgeNumber = 0
        }
    }
0 голосов
/ 30 января 2019

cancellAllLocalNotification устарела из iOS 10. из appledoc

устарела

Используйте класс UNUserNotificationCenter для планирования локальных уведомлений.

Использование

UNUserNotificationCenter.current().removeAllDeliveredNotifications() // For removing all delivered notification
UNUserNotificationCenter.current().removeAllPendingNotificationRequests() // For removing all pending notifications which are not delivered yet but scheduled. 

С Доставленное удаление appledoc

Используйте этот метод для удаления всех доставленных уведомлений вашего приложения из Центра уведомлений.Метод выполняется асинхронно, немедленно возвращаясь и удаляя идентификаторы в фоновом потоке.Этот метод не влияет на любые запросы на уведомления, которые запланированы, но еще не доставлены.

С Ожидает удаления appledoc

Этот метод выполняетсяасинхронно удаляет все ожидающие запросы на уведомление во вторичном потоке.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...