2

Anyone used this to cancel a previously scheduled Local Notification? I see it in the documentation but can't get it wired up in code.

UIApplication.SharedApplication.ScheduledLocalNotifications schedNoteList = new 
                 UIApplication.SharedApplication.ScheduledLocalNotifications();
        foreach(UILocalNotification sNote in schedNoteList)
        {
            if(sNote.FireDate == oldDate)
            {
                //Cancel the Notification
                UIApplication.CancelLocalNotification(sNote);
            }
        }

Thanks, Rick

poupou
  • 43,413
  • 6
  • 77
  • 174
Rick
  • 483
  • 1
  • 6
  • 19

1 Answers1

2

This code will compile:

    foreach(UILocalNotification sNote in UIApplication.SharedApplication.ScheduledLocalNotifications)
    {
        if(sNote.FireDate == DateTime.Now)
        {
            //Cancel the Notification'
            UIApplication.SharedApplication.CancelLocalNotification (sNote);
        }
    }

but I cannot say if it will do what you want it to do (since I mostly reworked your code using MonoDevelop code completion).

poupou
  • 43,413
  • 6
  • 77
  • 174
  • Works great except that you have to convert the FireDate to DateTime or the the other date to NSDate. And the compare date to UTC - Then I had to compare the string values to get it to work... Not sure why that was - if(NSDateToDateTime(sNote.FireDate).ToString() == oldDate.ToUniversalTime().ToString()) – Rick Aug 10 '11 at 21:14