uilocalnotification is not firing at exact time

血红的双手。 提交于 2019-12-01 08:21:53

UILocalNotification is designed for things that are happening far in the future so an error of 30 seconds would be OK (i.e. if I had a meeting at 15:00 then telling me at 15:00:30 wouldn't be a problem :)

If you want more accuracy than that you will need to keep your app running and use an NSTimer.

Jazzmanouch

I know this is an old question, but I have just figure this out, you can use the dateByAddingTimeInterval : method.

notif.fireDate = [[datePicker date] dateByAddingTimeInterval:-30];
Jyoti S.

You can set fireDate by using NSDateComponents, in which you can set seconds for firedate. When I set it to 0 doesn't work, but it works if I set it to 1 seconds. 1 second late will be OK compared to 30-40 seconds.

NSCalendar *cal = [NSCalendar currentCalendar];
    NSDateComponents *dateComps = [cal components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay |NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond   fromDate:fireDate];
    [dateComps setSecond:1];
    [dateComps setNanosecond:00];
    NSDate *newDate = [cal dateFromComponents:dateComps];
    fireDate = newDate;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!