简体   繁体   English

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

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

I need to protect my application from taking screenshot before going to background. 在进入后台之前,我需要保护我的应用程序免于截屏。 I have added a black view in applicationDidEnterBackground: . 我在applicationDidEnterBackground:添加了一个黑色视图。 But when I check background applications in iOS7 simulator it is not showing the black image instead it shows the application itself as shown in image. 但是,当我在iOS7模拟器中检查后台应用程序时,它没有显示黑色图像,而是显示了应用程序本身,如图所示。 How can I solve this? 我该如何解决? If I get notified before app goes background this problem might be solved. 如果我在应用程序进入后台之前收到通知,则可能会解决此问题。 Any help would be greatly appreciated. 任何帮助将不胜感激。 在此处输入图片说明

您将在AppDelegate的applicationDidEnterBackground获得回调

The best way to achieve the functionality you want throughout your entire app is making your app navigate to an entirely black UIViewController. 在整个应用程序中实现所需功能的最好方法是使应用程序导航到全黑的UIViewController。 This so you cannot see anything when you long press on the homebutton and see the background applications. 这样一来,当您长按主页按钮并查看后台应用程序时,您将看不到任何内容。

These 2 functions will do the trick: 这两个功能可以解决问题:

- (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