我如何知道我的应用程序是来自后台还是已经在前台
无论我的应用程序来自后台还是已经在前台,我都希望以不同的方式处理 APN。你知道什么方法可以帮助我吗?
I want to handle APNs differently whether my application come from background or is already in the foreground. Do you know what methods could help me ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这些是处理有关应用程序状态更改的通知的消息。
您必须在指定的代表中实现您需要的!请查看以下链接的“任务”部分以获得进一步帮助,特别是“监视应用程序状态更改”部分;-)
Apple 的 UIApplicationDelegate 协议参考
These are the messages that handle the notification about a changing application state.
You must implement the one's you need in the designated Delegate! Take a look at the "Task" section of the following link for further assistance, especially the "Monitoring application state changes" part ;-)
Apple's UIApplicationDelegate Protocol Reference
这是当app从后台转到前台时执行的方法。因此,您可以根据上述方法在此处编写代码,了解当应用程序从后台转到前台时您想要执行的任何操作。
It is a method which is executed when app comes to foreground from background. So you can write your code here under the above method about whatever you want to do when app comes to foreground from being in background.
请看一下 delegate.m 文件中编写的这些方法
Please have a look at these methods written in delegate.m file
您必须实现 application:didReceiveLocalNotification: 方法。这两种情况都会被调用。您可以通过检查 [UIApplication sharedApplication] 的 applicationState 属性来区分这两种情况:如果它是 UIApplicationStateInactive 则该应用程序位于后台,如果它是 UIApplicationStateActive 则该应用程序位于前台。
You must implement the application:didReceiveLocalNotification: method. This will be called for both cases. You can differentiate between the cases by checking the applicationState property of [UIApplication sharedApplication]: if it's UIApplicationStateInactive then the app was in background, and if it's UIApplicationStateActive then the app was in foreground.