iOS 5横幅推送通知消失,用户点击应用程序图标启动应用程序
在 iOS 5 中,推送通知可以显示为横幅并在几秒钟后消失。 据我所知,当用户点击横幅时将调用 didReceiveRemoteNotification 。
我的问题是,如果横幅消失并且我的用户看到应用程序上有徽章编号,他们将点击应用程序图标来启动应用程序。现在,如果应用程序在后台运行,我如何检查应用程序是否已进入前台并且已收到通知,并执行必要的操作?
我的通知的目的基本上是通知用户应用程序内容已更新,并鼓励他们运行应用程序以获取最新内容。我的应用程序仅在启动时检查最新内容,不会定期检查更新。
With iOS 5, push notifications can appear as banner and disappear after a few seconds.
I understand that didReceiveRemoteNotification will be called when user taps on the banner.
My question is, if the banner has disappeared and my user sees that there is a badge number on the app, they will tap on the app icon to start the app. Now if the app is running in the background, how do I check that the app is brought to foreground and there has been a notification, and do the necessary?
The purpose of my notification is basically to inform user there has been an update to the app content and encourage them to run the app to get the latest contents. My app only checks for latest contents at launch time and doesn't check for updates periodically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题有点老了,但无论如何我都会在这里找到我发现的内容。
您需要在应用程序委托中实现两种方法,以检查您的应用程序是否是从远程通知启动的(当应用程序未在您的设备上运行时),或者在运行时接收到远程通知(在后台或前台) )。
首先是您的应用程序委托中已有的方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
要检查这是否是从远程通知启动的,请使用一些与此类似的代码:
您需要实现的另一种方法专门针对您的应用程序运行时的情况:
如何处理来自那里的通知取决于您,但这就是您的应用程序了解的方式 它!
在第二种方法中,您可以检查传递的应用程序的 UIApplicationState 以确定您是在前台还是后台。
This question is a bit old, but I'll pop what I've found in here anyway.
There are two methods you need to implement in your app delegate to check if your app was either launched from the remote notification (From when the app is not running on your device), or received the remote notification while running (in the background or foreground).
First is a method that is already in your App Delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
To check if this was launched from a remote notification, have some code similar to this:
The other method you will need to implement is specifically for the case that your application for when your application is running:
How you handle the notification from there is up to you, but that's how your app knows about it!
In this second method, you can check the UIApplicationState of the passed application to find out if you were in the foreground or background.