问题
link1 link2
If I want to set local notification to repeat every 2 week than how to achieve this?
I have read several questions and answers here, they have mention to reschedule local notification but how to reschedule local notification while application is in background ?
I will appreciate any help on same.
Thanks.
回答1:
To reschedule UILocal Notification use this ,
NSDateFormatter *dat= [[NSDateFormatter alloc]init];
[dat setLocale:[NSLocale currentLocale]];
[dat setTimeZone:[NSTimeZone systemTimeZone]];
//[dat setDateFormat:@"YYYY-MM-dd"];// YYYY-MM-dd hh:mm a
//NSString *dateM=[dat stringFromDate:datM];
//[dat setDateFormat:@"YYYY-MM-dd h:mm a"];
NSDate *reminderDate=[NSDate date];
//Use manual option too for timing
reminderDate =[reminderDate dateByAddingTimeInterval:1*24*60*60*7];
UILocalNotification *localnoification = [[UILocalNotification alloc]init];
localnoification.fireDate=reminderDate;
localnoification.timeZone = [NSTimeZone defaultTimeZone];
localnoification.alertBody = word;
localnoification.alertAction = @"Tap to see word of the day";
//May Add Custom Sound Also
//localnoification.soundName = UILocalNotificationDefaultSoundName;
localnoification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
//localnoification.applicationIconBadgeNumber = 1;
localnoification.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localnoification];
来源:https://stackoverflow.com/questions/25175135/local-notification-every-2-week