xcode - (void)applicationDidEnterBackground:(UIApplication *)application
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4018050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
- (void)applicationDidEnterBackground:(UIApplication *)application
提问by SajjadZare
Can i use below method somewhere other than AppDelegate ?if yes how?
我可以在 AppDelegate 以外的其他地方使用下面的方法吗?如果是,如何?
- (void)applicationDidEnterBackground:(UIApplication *)application
回答by Ole Begemann
No, But you can have other objects register for the UIApplicationDidEnterBackgroundNotification
notification. These objects will then be notified at the same time applicationDidEnterBackground:
is called.
不,但是您可以让其他对象注册UIApplicationDidEnterBackgroundNotification
通知。然后这些对象会在applicationDidEnterBackground:
被调用的同时得到通知。
回答by Jacob Relkin
This is a method of the UIApplicationDelegate
protocol, and can only be implemented by classes that conform to it.
这是UIApplicationDelegate
协议的一个方法,只能由符合它的类来实现。
You can set up a notification to other objects in your app from your app delegate by using the NSNotificationCenter
object:
您可以使用以下NSNotificationCenter
对象从您的应用程序委托设置对应用程序中其他对象的通知:
- (void)applicationDidEnterBackground:(UIApplication *)application {
[[NSNotificationCenter defaultCenter] postNotificationName:@"didEnterBackground" object:self];
}
There is also the UIApplicationDidEnterBackgroundNotification
notification that you can listen for instead of doing the above.
还有一个UIApplicationDidEnterBackgroundNotification
,你可以听的,而不是做上述通知。
Register the objects that you want to listen for the notification like this:
像这样注册要监听通知的对象:
[[NSNotificationCenter defaultCenter] addObserver:someObject selector:@selector(someMethod:) name:@"UIApplicationDidEnterBackgroundNotification" object:nil];