NSTimer 在设备锁定时触发

发布于 2024-10-11 03:52:01 字数 356 浏览 0 评论 0原文

我目前正在创建警报。我使用 NSTimer 来安排闹钟。我的问题是当设备进入锁定模式时我的 NSTimer 不会触发。我认为 NSTimer 不会触发,因为我的应用程序在锁定时会进入挂起状态。你能帮我找到解决问题的方法吗?

我找到了一些有关 UIBackgroundModes 的主题,但我不知道它对我有什么帮助。

谢谢..

UILocalNotification 的问题是当设备处于静音状态时,将听不到声音。 我的实现是,当应用程序位于前台或设备被锁定但应用程序当前正在运行时,我使用 NSTimer 发出警报。当 applicationDidEnterBackground: 被调用时,我将 UILocalNotification 安排为警报。

I'm currently creating an alarm. I use NSTimer to schedule my alarms. My problem is when the device was put into locked mode my NSTimer doesn't fire. I think that the NSTimer will not fire because my app goes to suspended state when it is lock. Can you help me find a solution to my problem?

I've found some topics about UIBackgroundModes, but I don't know how it will help me.

Thanks..

The problem in UILocalNotification is when the device was in silent, the sound will not be hear.
My implementation was I'm using NSTimer to fire an alarm when the app is in foreground or device is locked but app currently running. When the applicationDidEnterBackground: is called I schedule the UILocalNotification as the alarm.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不顾 2024-10-18 03:52:01

您必须使用本地通知 (UILocalNotification) 才能实现此功能。

查看 Apple 文档了解更多信息细节。

You will have to use a local notification (UILocalNotification) for this to work.

Check out Apple's documentation for further details.

灼疼热情 2024-10-18 03:52:01

有一个小技巧可以让设备保持唤醒状态,即使用户锁定屏幕也是如此。

缺点是,它会消耗相当多的电池寿命。我不久前写了一篇关于如何执行此操作的博客文章。 操作方法:防止 iPhone 进入深度睡眠 - blog.marcopeluso.com

此技术适用于 iOS 4.2.1 及之前的所有 iOS 设备,并且我已获得批准App Store 上的闹钟应用程序使用此功能。

我创建了一段可供您使用的插入代码。 GitHub 上的 MMPDeepSleepPreventer

There is a little trick to keep the device awake, even if the user locks the screen.

The downside is, that it costs quite a lot of battery life. I've written a blog post on how to do this a while ago. How-To: Prevent iPhone from Deep Sleeping - blog.marcopeluso.com

This technique works on all iOS devices up to iOS 4.2.1 and I've got an approved alarm clock app on the App Store that uses this.

I have created a piece of drop-in code you can use. MMPDeepSleepPreventer on GitHub

计㈡愣 2024-10-18 03:52:01

您可以使用本地通知来实现此目的,即使您的应用程序在后台运行,您也可以通过本地通知接收警报。

您可以参考以下链接了解更多详细信息

http ://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html

干杯

You can use Local Notifications for this purpose,even if your app is running in the background you can receive alerts via Local Notifications.

You can refer the below link for further details

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html

Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文