0

I wanted to do something. My notifications are set to 11 and 12 hours. I would like to unsubscribe notification of these are set just hours 11. How do I make it?

My code;

NSCalendar *greg = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
        NSDateComponents * component = [greg components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];
        [component setYear:2013];
        [component setMonth:m];
        [component setDay:d];
        [component setHour:x];
        [component setMinute:y];

        UIDatePicker *dd = [[UIDatePicker alloc]init];
        [dd setDate:[greg dateFromComponents:component]];

        UILocalNotification * bildirim = [[UILocalNotification alloc]init];
        [bildirim setAlertBody:newtask.name];
        [bildirim setFireDate:dd.date];
        bildirim.soundName = UILocalNotificationDefaultSoundName;
        bildirim.alertAction = NSLocalizedString(@"Test", nil);
        //[bildirim setFireDate:[NSDate dateWithTimeIntervalSinceNow:0]];
        [bildirim setTimeZone:[NSTimeZone defaultTimeZone]];

        [[UIApplication sharedApplication] scheduleLocalNotification:bildirim];

I found a code. Unfortunately this code is deleting all notifications.

[[UIApplication sharedApplication] cancelAllLocalNotifications];

Sorry for my bad english.

Salieh
  • 693
  • 2
  • 7
  • 12

1 Answers1

0

Two things while you are creating local notification, create it with some unique identification so that you can identify like below

UILocalNotification * notification = [[UILocalNotification alloc]init];
notification.userInfo=[NSDictionary dictionaryWithObject:@"UNIQUE_ID" forKey:@"notifcation_id"];

Then to cancel the specific one you need the following steps

for(UILocalNotification *notificaiton in [[UIApplication sharedApplication] scheduledLocalNotifications]){

    if([[notificaiton.userInfo objectForKey:@"notifcation_id"] isEqualToString:UNIQUE_ID]){
        [[UIApplication sharedApplication] cancelLocalNotification:notificaiton];
        break;
    }
}

All the best..

iphonic
  • 12,615
  • 7
  • 60
  • 107
  • Trying to : http://pastie.org/7675392 Error: Use of undeclared identifier 'eventID' . What is the eventID? :S – Salieh Apr 20 '13 at 18:42
  • You cannot make this code run, you need to define your own `UniqueID/EventID`.. and using that ID you can track which notification you want to cancel.. – iphonic Apr 20 '13 at 18:57