Trong iOS 10, trên tất cả các giải pháp được khấu hao
'cancelAllLocalNotifications()' được tán thành trong iOS 10.0: Sử dụng UserNotifications Khung của - [UNUserNotificationCenter removeAllPendingNotificationRequests]
Sử dụng mã dưới đây để hủy thông báo và đặt lại Số lượng huy hiệu
Đối với iOS 10, Swift 3.0
cancelAllLocalNotifications
bị phản đối từ iOS 10.
@available(iOS, introduced: 4.0, deprecated: 10.0, message: "Use UserNotifications Framework's -[UNUserNotificationCenter removeAllPendingNotificationRequests]")
open func cancelAllLocalNotifications()
Bạn sẽ phải thêm tuyên bố nhập khẩu này, trung tâm thông báo
import UserNotifications
Nhận. Và thực hiện thao tác như bên dưới
application.applicationIconBadgeNumber = 0 // For Clear Badge Counts
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.
Nếu bạn muốn xóa một hoặc nhiều thông báo cụ thể, bạn có thể thực hiện theo phương thức dưới đây.
center.removeDeliveredNotifications(withIdentifiers: ["your notification identifier"])
Hy vọng nó sẽ giúp .. !!
Nguồn
2017-10-29 08:01:16
Sử dụng cancelAllLocalNotifications? Đây là thông báo từ xa. Cảm ơn ý kiến. – Tedha
Rất tiếc, tôi đã nhầm lẫn với các thông báo địa phương như tôi thường sử dụng cả hai cùng một lúc. – Icaro
Hoặc có thể điều này cũng có thể giúp quá http://stackoverflow.com/questions/10971825/remove-remote-notifications-from-notification-center – Icaro