uilocalnotification 没有在准确的时间触发
我想在我的应用程序中实现uilocalnotification
。但问题是它没有在准确的时间发射。它在给定发射时间后 30 - 40 秒后发射。 是否有我遗漏的东西,或者这是 UILocalNotification
中的常见想法。
谢谢
I want to implement uilocalnotification
in my app. but the problem is that it is not firing at the exact time. it is firing after 30 - 40 secs from the given firing time.
Is there something I am missing or this is a common think in UILocalNotification
.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UILocalNotification 是为遥远的未来发生的事情而设计的,因此 30 秒的错误是可以接受的(即,如果我在 15:00 开会,那么在 15:00:30 告诉我就不成问题了:)
如果您想要比保持应用程序运行和使用 NSTimer 所需的更高的准确性。
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.
我知道这是一个老问题,但我刚刚弄清楚,你可以使用
dateByAddingTimeInterval:
方法。I know this is an old question, but I have just figure this out, you can use the
dateByAddingTimeInterval :
method.您可以使用
NSDateComponents
来设置fireDate
,在其中您可以设置firedate的秒数。当我将其设置为 0 时不起作用,但如果将其设置为 1 秒则有效。与延迟 30-40 秒相比,延迟 1 秒就可以了。You can set
fireDate
by usingNSDateComponents
, 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.