My UIViewController
registers for notifications which my model component sends out when it has finished downloading content.
我的UIViewController注册我的模型组件在下载完内容后发出的通知。
The downloading can occur in the background (by using beginBackgroundTaskWithExpirationHandler:
) so obviously I don't want my GUI to attempt to redraw etc. if the download completes in the background.
下载可以在后台进行(通过使用beginBackgroundTaskWithExpirationHandler :)所以显然我不希望我的GUI尝试重绘等,如果下载在后台完成。
So I guess I have two choices - 1) the model knows when its in the background/foreground and doesn't fire the notifications. 2) the UIViewController
deregisters for notifications when its in the background.
所以我想我有两个选择 - 1)模型知道它在后台/前景中的时间并且不会触发通知。 2)UIViewController在后台取消注册通知。
Option 2) is preferable.
选项2)是更可取的。
Is there a method on UIViewController
that is always called when the app goes into the background? Or will the UIViewController
have to register to receive a notification event when the app moves into the background?
UIViewController上是否有一个方法,当应用程序进入后台时总是被调用?或者当应用程序进入后台时,UIViewController是否必须注册才能收到通知事件?
(Seems like viewWillDisappear
, viewWillUnload
etc. don't get called when the app moves to the background?)
(看起来像viewWillDisappear,viewWillUnload等,当app移动到后台时不会被调用?)
1 个解决方案
#1
23
make your view controller register for UIApplicationDidEnterBackgroundNotification
in view did load
... the selector method associated will be called before entering background..
让你的视图控制器注册UIApplicationDidEnterBackgroundNotification在视图中加载...相关的选择器方法将在进入后台之前被调用。
#1
23
make your view controller register for UIApplicationDidEnterBackgroundNotification
in view did load
... the selector method associated will be called before entering background..
让你的视图控制器注册UIApplicationDidEnterBackgroundNotification在视图中加载...相关的选择器方法将在进入后台之前被调用。