I have a problem with my UILocalNotification.
I am scheduling the notification with my method.
- (void) sendNewNoteLocalReminder:(NSDate *)date a
In swift, you first add a dict to notifications userInfo by:
let dict:NSDictionary = ["ID" : "someString"]
notification.userInfo = dict as! [String : String]
Then, you want to get an array of existing notifications (2), and iterate through each one (3) until you find the one you're looking for. Once you find it, cancel it (4).
// 1. Pass in the string you want to cancel
func cancelLocalNotification(uniqueId: String){
// 2. Create an array of notifications, ensuring to use `if let` so it fails gracefully
if let notifyArray = UIApplication.sharedApplication().scheduledLocalNotifications {
// 3. For each notification in the array ...
for notif in notifyArray as [UILocalNotification] {
// ... try to cast the notification to the dictionary object
if let info = notif.userInfo as? [String: String] {
// 4. If the dictionary object ID is equal to the string you passed in ...
if info["ID"] == uniqueId {
// ... cancel the current notification
UIApplication.sharedApplication().cancelLocalNotification(notif)
}
}
}
}
}