zeiteisen
zeiteisen

Reputation: 7168

UILocalNotification Schedule Daily Until Date

I already schedule a daily notification with this code:

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];

But I miss a expire date. The notification should end on christmas without that the user has to start the app. Is this possible?

Upvotes: 1

Views: 290

Answers (1)

Yogesh Suthar
Yogesh Suthar

Reputation: 30488

You can't specify expiry date in UILocalNotification. Instead you will need to create UILocalNotification till christmas. But there is also a limit of 64 UILocalNotification.

Upvotes: 1

Related Questions