iOS 开发:推送通知阻止我的本地通知触发

发布于 2024-10-12 16:53:31 字数 331 浏览 3 评论 0原文

我有一个闹钟应用程序,该应用程序设计为在前台运行时以特定方式运行,并且它收到由我的应用程序安排的本地通知。当用户设置闹钟时,我的应用程序会创建本地通知。当本地通知触发时,它会调用 didReceiveLocalNotification 方法来提醒用户。问题是,如果我的应用程序在前台运行并且推送通知来自不同的应用程序,那么它会显示模式推送通知视图,这会阻止我的应用程序在本地通知触发时向用户发出警报。一旦我关闭推送通知模式视图,我的应用程序就会触发本地通知。有办法解决这个问题吗?我问这个问题是因为,如果我的应用程序在用户安排其触发时没有触发警报,那么它就有点违背了设置警报的全部目的。

非常感谢您的智慧!

I have an alarm clock app that's designed to function in a specific way when it's running in the foreground and it receives a local notification that was schedule by my app. When the user sets an alarm, my app creates a local notification. When that local notification fires, it calls the didReceiveLocalNotification method to alert the user. The problem is, if my app is running in the foreground and push notification comes in from a different app, then it displays the modal push notification view, which prevents my app from alerting the user when the local notification fires. As soon as I dismiss the push notification modal view, then my app fires the local notification. Is there a way around this? I ask because if my app doesn't set off the alarm when the user schedules it to fire, then it kinda defeats the whole purpose of setting an alarm.

Thanks so much for your wisdom!

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

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

发布评论

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

评论(2

¢好甜 2024-10-19 16:53:32

应用程序有 5 种不同的状态:

  • 前台活动
  • 前台非活动
  • 后台运行
  • 后台挂起
  • 未运行

当您启动应用程序时,它处于“前台活动”状态,然后,当显示模式推送通知时,您的应用程序将进入“前台非活动”状态。

苹果在文档中说(http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html):

如果它在应用程序在前台未处于活动状态时传递它,它会显示警报、标记应用程序图标或播放声音 - 无论 UILocalNotification 对象中指定什么。如果应用程序在前台运行,则不会出现警报、标记或声音;相反,如果委托实现了 application:didReceiveLocalNotification: 方法,则会调用该方法。

因此,在前台,仅当您的应用程序处于活动状态时才会调用 application:didReceiveLocalNotification: ,并且当您关闭模式通知时它会变为活动状态。

这是临界点,这种情况没有解决方案。

There is 5 different states for an application:

  • Foreground Active
  • Foreground Inactive
  • Backgroung Running
  • Backgroung Suspended
  • Not Running

When you launch your application, it's in "Foreground Active" then, when the modal push notification is displayed your application goes to "Foreground Inactive".

In the documentation, Apple said (http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html):

If it delivers it when the application is not active in the foreground, it displays an alert, badges the application icon, or plays a sound—whatever is specified in the UILocalNotification object. If the application is running in the foreground, there is no alert, badging, or sound; instead, the application:didReceiveLocalNotification: method is called if the delegate implements it.

So in the foreground, application:didReceiveLocalNotification: gets called only if your app si active, and it become active when you dismiss the modal notification.

This is borderline and there is no solution for this case.

梅倚清风 2024-10-19 16:53:32

我不相信有办法解决这个问题。您也许可以播放声音或振动,但操作系统已经通过推送通知警报来请求用户注意,因此在用户处理第一个警报之前发布另一个警报实际上没有任何帮助。当用户同时安排两个闹钟时,您如何处理?

I don't believe there's a way around it. You might be able to play a sound or vibrate, but the OS is already asking for the user's attention with the push notification alert, so it really won't help to post another one until the user deals with the first. How do you handle things when the user schedules two alarms at the same time?

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