2017-01-04 50 views

回答

0

試試這個,

UNUserNotificationCenter.current().getDeliveredNotifications { notifications in 

    let yesterday = NSCalendar.current.date(byAdding: .day, value: -1, to: Date())! 

    let identifiersToRemove = notifications 
     .filter { $0.date.compare(yesterday) == .orderedAscending } 
     .map { $0.request.identifier } 

    UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiersToRemove) 
} 
相關問題