iPhone: How to set repeat daily/hourly local notification?

亡梦爱人 提交于 2019-11-29 02:44:20

If you want to set the Notifications at a particular time on daily ... .then you need to set the notification repeatInterval property.iOS handles of it;s own about the notification.Just add this single line ...which you missed out. Otherwise you code is fine & will work.

notif.repeatInterval = NSDayCalendarUnit;

Your code would be much simpler if you used dateByAddingComponents:toDate:options:.

(dateByAddingTimeInterval: does not handle calendars properly, e.g. time zone changes.)

If you want it to repeat, I think you have to add several, or re-add them when your app is next launched. Otherwise, a notification that repeated every second would be incredibly annoying.

SURESH SANKE
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil) return;

NSDate *fireTime = [[NSDate date]   dateByAddingTimeInterval:900]; // 15 minutes

localNotif.fireDate = fireTime;
localNotif.alertBody = @"15 min reached";
localNotif.repeatInterval=kCFCalendarUnitMinute;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!