notification
のuserInfo
にキーとなるものを設定しておけば、それを狙って消すことができます。
swift
1
2@IBAction func setLocalNotification(sender: UIButton) {
3
4 let notification = UILocalNotification()
5 notification.fireDate = Date(timeIntervalSinceNow: 5)
6 notification.timeZone = NSTimeZone.default
7 notification.alertBody = "Alert Body"
8 notification.alertAction = "OK"
9 notification.userInfo = ["id": "12345", "time": Date()]
10 notification.soundName = UILocalNotificationDefaultSoundName
11 UIApplication.shared.scheduleLocalNotification(notification)
12}
13
14@IBAction func cancellNotification(_ sender: UIButton) {
15 for notification in UIApplication.shared.scheduledLocalNotifications ?? [] {
16 if let id = notification.userInfo?["id"] as? String, id == "12345" {
17 UIApplication.shared.cancelLocalNotification(notification)
18 }
19 }
20}
21
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。