我想每年在特定日期触发本地通知,但所有通知都有不同的标题和正文,这是我编写的代码,效果很好,但仅适用于一个通知,第二部分是在收到通知后我的应用程序图标有 1 , 表示那里的一个通知如何删除它?..
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UIApplication.shared.statusBarStyle = .default
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]){ (allowed, error) in
UNUserNotificationCenter.current().delegate = self
scheduleNotification()
return true
}
func scheduleNotification() {
var date = DateComponents()
date.year = 2017
date.month = 6
date.day = 12
date.hour = 22
date.minute = 39
let trigger = UNCalendarNotificationTrigger(dateMatching: date, repeats: false)
let content = UNMutableNotificationContent()
content.title = "Schedule Notification"
content.body = "Today is my Birthday"
content.sound = UNNotificationSound.default()
content.badge = 1
let request = UNNotificationRequest(identifier: "textNotification", content: content, trigger: trigger)
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print("error: \(error)")
}
}
提前感谢和感谢