Iphone 4 sdk - 如何查明 applicationWillEnterForeground 是否因通知而触发?
我正在使用通知系统作为警报机制。如果应用程序关闭或在后台,当有通知到来时,iPhone 会提醒用户。如果应用程序正在运行并且在前台,我想显示与关闭时相同的警报视图。我无法让它在应用程序从后台转换到前台的情况下工作。如果转换是由于通知引起的,我最终会看到两次警报,如果用户单击启动图标,我最终会看到一次警报。
有什么方法可以知道转换是否是由于用户单击启动图标而发出的通知?
谢谢。
I am using the notification system as an alerting mechanism. If the app is off or in the background, the iphone alerts the user when a notification comes in. If the app is running and in the foreground I want to show the same alert view as if it was off. I cannot get this to work for the case where the app transitions from the background to the foreground. I end up seeing the alert twice if the the transition was due to a notification, or once if the user clicked the launch icon.
Is there any way to know whether the transition was due to a notification of due to the user clicking the launch icon?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题提供了答案。
具体来说,在 didReceiveRemoteNotification 方法中,您可以检查应用程序的状态。 UIApplicationStateActive 意味着它位于前台,因此您需要显示警报。否则 Iphone 将处理警报:
This question provides the answer.
Specifically, in the didReceiveRemoteNotification method you can check the state of the app. UIApplicationStateActive means it is in the foreground so you need to show the alert. Otherwise the Iphone will handle the alert: