Creating, configuring, and scheduling a local notification

来源:互联网 发布:中国移动m823软件 编辑:程序博客网 时间:2024/06/07 14:24
- (void)scheduleNotificationWithItem:(ToDoItem *)item interval:(int)minutesBefore {    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];    NSDateComponents *dateComps = [[NSDateComponents alloc] init];    [dateComps setDay:item.day];    [dateComps setMonth:item.month];    [dateComps setYear:item.year];    [dateComps setHour:item.hour];    [dateComps setMinute:item.minute];    NSDate *itemDate = [calendar dateFromComponents:dateComps];    UILocalNotification *localNotif = [[UILocalNotification alloc] init];    if (localNotif == nil)return;    localNotif.fireDate = [itemDatedateByAddingTimeIntervalInterval:-(minutesBefore*60)];    localNotif.timeZone = [NSTimeZone defaultTimeZone];    localNotif.alertBody = [NSString stringWithFormat:NSLocalizedString(@"%@ in%i minutes.", nil),         item.eventName, minutesBefore];    localNotif.alertAction = NSLocalizedString(@"View Details", nil);    localNotif.soundName = UILocalNotificationDefaultSoundName;    localNotif.applicationIconBadgeNumber = 1;    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:item.eventNameforKey:ToDoItemKey];    localNotif.userInfo = infoDict;    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];}

0 0