我如何知道我的应用程序是来自后台还是已经在前台

发布于 2024-11-27 06:17:19 字数 58 浏览 1 评论 0原文

无论我的应用程序来自后台还是已经在前台,我都希望以不同的方式处理 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 技术交流群。

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

发布评论

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

评论(4

深居我梦 2024-12-04 06:17:19

这些是处理有关应用程序状态更改的通知的消息。

– application:didFinishLaunchingWithOptions:
– applicationDidBecomeActive:
– applicationWillResignActive:
– applicationDidEnterBackground:
– applicationWillEnterForeground:
– applicationWillTerminate:
– applicationDidFinishLaunching:

您必须在指定的代表中实现您需要的!请查看以下链接的“任务”部分以获得进一步帮助,特别是“监视应用程序状态更改”部分;-)

Apple 的 UIApplicationDelegate 协议参考

These are the messages that handle the notification about a changing application state.

– application:didFinishLaunchingWithOptions:
– applicationDidBecomeActive:
– applicationWillResignActive:
– applicationDidEnterBackground:
– applicationWillEnterForeground:
– applicationWillTerminate:
– applicationDidFinishLaunching:

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

傲性难收 2024-12-04 06:17:19
- (void)applicationDidBecomeActive:(UIApplication *)application

这是当app从后台转到前台时执行的方法。因此,您可以根据上述方法在此处编写代码,了解当应用程序从后台转到前台时您想要执行的任何操作。

- (void)applicationDidBecomeActive:(UIApplication *)application

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.

空心↖ 2024-12-04 06:17:19
  • (void)applicationWillResignActive:(UIApplication *)application;
  • (void)applicationDidEnterBackground:(UIApplication *)application;
  • (void)applicationWillEnterForeground:(UIApplication *)application;
  • (void)applicationDidBecomeActive:(UIApplication *)application ;

请看一下 delegate.m 文件中编写的这些方法

  • (void)applicationWillResignActive:(UIApplication *)application;
  • (void)applicationDidEnterBackground:(UIApplication *)application;
  • (void)applicationWillEnterForeground:(UIApplication *)application;
  • (void)applicationDidBecomeActive:(UIApplication *)application ;

Please have a look at these methods written in delegate.m file

丑疤怪 2024-12-04 06:17:19

您必须实现 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.

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