如何在祷告时间每天不同的时间设置本地通知重复间隔?
问题描述:
在本地通知中有repeatInterval属性,我们可以将分钟,小时,星期,星期,年份等单位重复间隔。如何在祷告时间每天不同的时间设置本地通知重复间隔?
我希望祷告时间和每天的相同过程的重复时间间隔。
所以每个祷告时间小时当地通知来。
祈祷时间每天都在不同时间
我该怎么做?
答
只要试试这个:
NSCalendar *calen = [NSCalendar autoupdatingCurrentCalendar] ;
NSDateComponents *components = [calen components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:[NSDate date]];
[components setHour:9];
[components setMinute:30];
[components setSecond:00];
UILocalNotification *notif = [[UILocalNotification alloc]init];
notif.fireDate = [calen dateFromComponents:components];
notif.repeatInterval = NSCalendarUnitDay;
[notif setAlertBody:@"Its prayer time..."];
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
希望它会为你工作。
+0
但每天的时间是不同的,每天安排 –
+0
是的,我已经祈祷了时间计算方法。每天不同时间也得到时间 –
+0
? –
我建议为每天的祈祷小时创建一个本地通知,重复间隔为1天。 – Larme
@Larme,据我所知,祈祷时间每天都在变化,至少其中一些是基于日落/日出之类的。 – jcaron
@jcaron你是对的 –