本地添加及取消日期时间提醒

来源:互联网 发布:无实体软件出口 编辑:程序博客网 时间:2024/05/17 03:24

本地添加日期时间提醒

 NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];[calendar setTimeZone:[NSTimeZone localTimeZone]];NSDateComponents *dateComponents = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:[NSDate date]];NSArray * dateA = [dic[@"ReminderTime"] componentsSeparatedByString:@" "];NSArray *dateYear = [dateA.firstObject componentsSeparatedByString:@"/"];NSArray *dateTime = [dateA.lastObject componentsSeparatedByString:@":"];[dateComponents setYear:[dateYear.firstObject intValue]];[dateComponents setMonth:[dateYear[1] intValue]];[dateComponents setDay:[dateYear.lastObject intValue]];[dateComponents setHour:[dateTime.firstObject intValue]];[dateComponents setMinute:[dateTime[1] intValue]];[dateComponents setSecond:[dateTime.lastObject intValue]];NSDate *notificationDate = [calendar dateFromComponents:dateComponents];UILocalNotification *localNotif = [[UILocalNotification alloc] init];localNotif.alertBody = [NSString stringWithFormat:@"记事提醒 %@",dic[@"Title"]];localNotif.alertAction = dic[@"Title"];localNotif.soundName = UILocalNotificationDefaultSoundName;localNotif.fireDate = notificationDate;localNotif.timeZone = [NSTimeZone defaultTimeZone];NSMutableDictionary *dicUserInfo = [NSMutableDictionary dictionary];dicUserInfo = dic.mutableCopy;  localNotif.userInfo = dicUserInfo;localNotif.applicationIconBadgeNumber = 1;[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

本地取消日期时间提醒

 [[UIApplication sharedApplication] cancelLocalNotification:cancelNoti];
原创粉丝点击