如何从 viewController 访问 applicationDidEnterBackground [英] How to access applicationDidEnterBackground from viewController

查看:15
本文介绍了如何从 viewController 访问 applicationDidEnterBackground的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 viewController 调用 AppDelegate 中的 applicationDidEnterBackground ?

How can I call applicationDidEnterBackground that in AppDelegate from a viewController?

我想在不按主页按钮的情况下在应用程序后台运行一个功能.

I want to run a function in the background of the app without pressing home button.

推荐答案

您不应该从任何地方调用该函数.它会在应用程序进入后台时通知您.

You are not supposed to call that function from anywhere. It is there to let you know when the app enters the background.

您只是想知道应用何时进入后台?如果是这样,那么您可以创建一个通知来帮助您:

Do you simply want to know when the app enters the background? If so, then you can create a notification to help you with that:

[[NSNotificationCenter defaultCenter] addObserver: self
                                         selector: @selector(handleEnteredBackground:) 
                                             name: UIApplicationDidEnterBackgroundNotification
                                           object: nil];

这篇关于如何从 viewController 访问 applicationDidEnterBackground的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆