标签:
UILocalNotification* localNotification = [[UILocalNotification alloc]init];
localNotification.alertBody = @"this is a local notification";
localNotification.soundName = UILocalNotificationDefaultSoundName;
//schedule the time to push local notification
NSCalendar* calendar = [NSCalendar autoupdatingCurrentCalendar];
NSDate* currentDate = [NSDate date];
NSDateComponents* currentDateComponents = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:currentDate];
NSDateComponents* scheduledDateComponents = currentDateComponents;
if (currentDateComponents != nil) {
[scheduledDateComponents setDay:currentDateComponents.day + 7];
[scheduledDateComponents setHour:17];
[scheduledDateComponents setMinute:0];
[scheduledDateComponents setSecond:0];
}
NSDate* scheduledDate = [calendar dateFromComponents:scheduledDateComponents];
localNotification.fireDate = scheduledDate;
[[UIApplication sharedApplication]cancelAllLocalNotifications];
[[UIApplication sharedApplication]scheduleLocalNotification:localNotification];
/////SIMPLE WAY
http://stackoverflow.com/questions/10060578/uilocalnotification-fires-immediately-instead-of-at-scheduled-time
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
localNotification.alertBody = @"Your alert message";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
标签:
原文地址:http://www.cnblogs.com/yibinpan/p/4440991.html