UILocalNotification Schedule每日直到日期

时间:2014-08-27 11:26:08

标签: ios notifications uilocalnotification

我已使用此代码安排每日通知:

NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:7];
[components setMonth:3];
[components setYear:2014];
[components setHour:9];
NSInteger minute = arc4random() % 59;
[components setMinute:minute];
[components setSecond:0];
[calendar setTimeZone:[NSTimeZone defaultTimeZone]];
NSDate *dateToFire = [calendar dateFromComponents:components];

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.userInfo = @{@"uid": DailyNotificationUid};
localNotification.fireDate= dateToFire;
localNotification.timeZone = [NSTimeZone defaultTimeZone];

NSString *body = NSLocalizedString(@"Local Notification Alert Body", nil);
localNotification.alertBody = body;
localNotification.alertAction = NSLocalizedString(@"Local Notification Alert Action", nil);
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = 1;
localNotification.repeatInterval = NSCalendarUnitDay;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

但我错过了过期日期。通知应该在圣诞节结束,而用户不必启动应用程序。这可能吗?

1 个答案:

答案 0 :(得分:1)

您无法在UILocalNotification中指定到期日期。相反,你需要创建UILocalNotification直到圣诞节。但也有64 UILocalNotification的限制。

相关问题