繁体   English   中英

当应用程序进入后台时如何获得通知?

[英]How to get notified when application goes background?

在进入后台之前,我需要保护我的应用程序免于截屏。 我在applicationDidEnterBackground:添加了一个黑色视图。 但是,当我在iOS7模拟器中检查后台应用程序时,它没有显示黑色图像,而是显示了应用程序本身,如图所示。 我该如何解决? 如果我在应用程序进入后台之前收到通知,则可能会解决此问题。 任何帮助将不胜感激。 在此处输入图片说明

您将在AppDelegate的applicationDidEnterBackground获得回调

在整个应用程序中实现所需功能的最好方法是使应用程序导航到全黑的UIViewController。 这样一来,当您长按主页按钮并查看后台应用程序时,您将看不到任何内容。

这两个功能可以解决问题:

- (void) applicationDidEnterBackground:(UIApplication *)application
{
    //navigate to the black view controller
    BlackViewController *controller = [[BlackViewController alloc] init];

    [yourNavigationController pushViewController:viewController animated:yourAnimationSettings];

    [controller release];   
}

- (void) applicationWillEnterForeground:(UIApplication *)application
{
    //pop the black view controller so the user won't be bothered with it
    if(/*Check if your BlackViewController is the top of your navigationController stack*/)
    {
         [yourNavigationController popViewControllerAnimated:yourAnimationSettings];
    }
} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM