0

Every time i open the app, a local notification gets scheduled.

The issue is - the more times the viewDidLoad method fires, the more notifications get scheduled.

My goal is to filter the scheduled notifications (remove all existing) with specific userInfo and schedule the new one.

I've been using this code snippet for filtering the existing notifications before

let app:UIApplication = UIApplication.sharedApplication()
            for oneEvent in app.scheduledLocalNotifications! {
                let notification = oneEvent as UILocalNotification
                let sweetness = notification.userInfo
                if sweetness == nil {

                } else {
                    let userInfoCurrent = notification.userInfo! as! [String:AnyObject]
                    let uid = userInfoCurrent["uid"]! as! String
                    if uid == "uid1" {
                        //Cancelling local notification
                        app.cancelLocalNotification(notification)
                        break;
                    }
                    if uid == "uid2" {
                        app.cancelLocalNotification(notification)
                        break;
                    }}

The issue with this code - it simply doesn't work. None of the notifications with appropriate userInfo are removed (i check the local notifications count afterwards).

Can you guys suggest any new approaches or please review this code?

Thank you.

David Robertson
  • 1,561
  • 4
  • 19
  • 41

0 Answers0