Для прошивки 10, Swift 3,0
cancelAllLocalNotifications
осуждается от прошивки 10.
@available(iOS, introduced: 4.0, deprecated: 10.0, message: "Use UserNotifications Framework's -[UNUserNotificationCenter removeAllPendingNotificationRequests]")
open func cancelAllLocalNotifications()
Вы должны добавить оператор импорта,
import UserNotifications
Получить центр уведомлений. И выполните операцию, как показано ниже
let center = UNUserNotificationCenter.current()
center.removeAllDeliveredNotifications() // To remove all delivered notifications
center.removeAllPendingNotificationRequests() // To remove all pending notifications which are not delivered yet but scheduled.
Если вы хотите удалить одно или несколько конкретных уведомлений, вы можете получить его методом ниже.
center.removeDeliveredNotifications(withIdentifiers: ["your notification identifier"])
Надеюсь, это поможет .. !!
для уведомлений iOS10, что вы используете? используете ли вы систему «UserNotifications»? – Wolverine
Да, я использую структуру UNUserNotifications – technerd
Интересно, 'cancelAllLocalNotifications()' работает для меня в iOS 10.2. – kelin