Local Notification every 2 week

烂漫一生 提交于 2019-12-12 02:38:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!