Add Local Notification at particular time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AppDelegate.m | |
// | |
- (void)applicationDidEnterBackground:(UIApplication *)application | |
{ | |
NSDate *alertTime = [[NSDate date] | |
dateByAddingTimeInterval:10]; | |
NSDate *alertTime2 = [[NSDate date] | |
dateByAddingTimeInterval:30]; | |
NSCalendar *cal = [NSCalendar currentCalendar]; | |
NSDateComponents *comps = [[NSDateComponents alloc] init]; | |
[comps setDay:25]; | |
[comps setMonth:4]; | |
[comps setYear:2013]; | |
[comps setHour:13]; | |
[comps setMinute:46]; | |
NSDate *alertTime3 = [cal dateFromComponents:comps]; | |
NSLog(@"%@", [NSDate date]); | |
NSLog(@"%@", alertTime); | |
NSLog(@"%@", alertTime2); | |
NSLog(@"%@", alertTime3); | |
[self addNewSchedult:alertTime]; | |
[self addNewSchedult:alertTime2]; | |
[self addNewSchedult:alertTime3]; | |
} | |
- (void)addNewSchedult:(NSDate *)d { | |
UIApplication* app = [UIApplication sharedApplication]; | |
UILocalNotification* notifyAlarm = [[UILocalNotification alloc] init]; | |
if (notifyAlarm) | |
{ | |
notifyAlarm.fireDate = d; | |
notifyAlarm.timeZone = [NSTimeZone defaultTimeZone]; | |
notifyAlarm.repeatInterval = 0; | |
// notifyAlarm.soundName = @"abc.mp3"; | |
notifyAlarm.alertBody = [NSString stringWithFormat: @"Time is money! %@", d]; | |
[app scheduleLocalNotification:notifyAlarm]; | |
} | |
} |
Cancel one particular LocalNotification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIApplication *app = [UIApplication sharedApplication]; | |
NSArray *events = [app scheduledLocalNotifications]; | |
cancelNid = @"1"; | |
for (int i=0; i<[events count]; i++) | |
{ | |
UILocalNotification* notify = [eventArray objectAtIndex:i]; | |
NSString *uid = [NSString stringWithFormat:@"%@",[notify.userInfo valueForKey:@"nid"]]; | |
if ([nid isEqualToString:cancelNid]) | |
{ | |
[app cancelLocalNotification:notify]; | |
break; | |
} | |
} |