我遇到了一個涉及停止本地通知的問題。這個停止按鈕就是這樣,如果用戶啓動一個定時器(一旦定時器用完就彈出一個通知),然後決定他們不再需要定時器,他們可以取消它。這裏的問題是,我嘗試過的每種方法都不能阻止通知發生。這主要是因爲這些方法已過時。下面是我的代碼,我想知道是否有人對如何阻止通知停止有任何想法。任何幫助將非常感激。使用swift停止通知3
//In the view did load section
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
if granted {
print("granted")
} else {
print("not granted")
}
}
//in a seperate function
let center = UNUserNotificationCenter.current()
content.title = "Local notification"
content.categoryIdentifier = "alarm"
content.userInfo = ["customData": "fizzbuzz"]
content.sound = UNNotificationSound.init(named: "1.mp3")
content.badge = 1
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: time, repeats: false)
let request = UNNotificationRequest(identifier: "requestAlarm", content: content, trigger: trigger)
center.add(request)
center.delegate = self
我沒有看到任何取消代碼。 – matt
是的,我已經刪除它,因爲正如我所說,它是在IOS 10 – imjonu