简体   繁体   中英

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: . 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. 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. 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];
    }
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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