Display a view or splash screen before applicationDidEnterBackground (to avoid active view screenshot)

后端 未结 8 711
小鲜肉
小鲜肉 2020-11-27 15:40

I have confidential informations in my app, so I would like to hide them with a splash screen when the app is about to be moved to background.

I do run the app on iO

相关标签:
8条回答
  • 2020-11-27 15:45

    Had the same issue, essentially I was using applicationDidEnterBackground to show a UIWindow on top of the content, but in iOS8 it didn't work as it did in iOS7.

    The solution I found was to create the UIWindow in applicationWillResignActive but make it hidden securityWindow.hidden = YES; and then in applicationDidEnterBackground all I would do would be to change securityWindow.hidden = NO.

    This seems to work exactly as iOS7 obscuring the content when multi tasking without affecting the view when using NotificationCenter or ControlPanel.

    0 讨论(0)
  • 2020-11-27 15:48

    Need to write the code as follows:

    -(void)applicationWillResignActive:(UIApplication *)application
    {
        imageView = [[UIImageView alloc]initWithFrame:[self.window frame]];
        [imageView setImage:[UIImage imageNamed:@"Portrait(768x1024).png"]];
        [self.window addSubview:imageView];
    }
    

    Here to remove the imageview:

    - (void)applicationDidBecomeActive:(UIApplication *)application
    {
        if(imageView != nil) {
            [imageView removeFromSuperview];
            imageView = nil;
        }
    }
    

    It is working and properly tested.

    0 讨论(0)
  • 2020-11-27 15:49

    Swift 3.0 Answer for those who are to lazy to translate.

    func applicationDidEnterBackground(_ application: UIApplication) {
    
        let imageView = UIImageView(frame: self.window!.bounds)
        imageView.tag = 101
        imageView.image = ...
    
        UIApplication.shared.keyWindow?.subviews.last?.addSubview(imageView)
     }
    
    func applicationWillEnterForeground(_ application: UIApplication) {
    
        if let imageView : UIImageView = UIApplication.shared.keyWindow?.subviews.last?.viewWithTag(101) as? UIImageView {
            imageView.removeFromSuperview()
        }
    
    }
    
    0 讨论(0)
  • 2020-11-27 15:50

    I think this will help for Swift 3.0

    func applicationWillResignActive(_ application: UIApplication) {
    
            let imageView = UIImageView(frame: self.window!.bounds)
            imageView.tag = 101
            imageView.backgroundColor = UIColor.white
            imageView.contentMode = .center
            imageView.image = #image#
            UIApplication.shared.keyWindow?.subviews.last?.addSubview(imageView)
    
        }
    
    func applicationWillEnterForeground(_ application: UIApplication) {
            ReachabilityManager.shared.stopMonitoring()
            if let imageView : UIImageView = UIApplication.shared.keyWindow?.subviews.last?.viewWithTag(101) as? UIImageView {
                imageView.removeFromSuperview()
            }
        }
    
    0 讨论(0)
  • 2020-11-27 15:56

    Don't know why, but none of the methods described here worked for me. I was simply trying to cover the screen for security reasons. So, what helped was a Technical Q&A from Apple: https://developer.apple.com/library/ios/qa/qa1838/_index.html

    I guess the main difference is using a UIViewController? Anyways, the following code works perfectly for me on IOS 9.1:

    - (void)applicationDidEnterBackground:(UIApplication *)application
    {     
        UIViewController *blankViewController = [UIViewController new];
        blankViewController.view.backgroundColor = [UIColor blackColor];
    
        [self.window.rootViewController presentViewController:blankViewController animated:NO completion:NULL];
    }
    
    - (void)applicationWillEnterForeground:(UIApplication *)application
    {
        [self.window.rootViewController dismissViewControllerAnimated:NO completion:NO];
    }
    
    0 讨论(0)
  • 2020-11-27 15:56
    @interface MyAppDelegate ()
    @property (strong, nonatomic) MySplashView *splashView;
    @end
    @implementation MyAppDelegate
    - (void)applicationWillResignActive:(UIApplication *)application {
        // hide keyboard and show a splash view
        [self.window endEditing:YES];
        MySplashView *splashView = [[MySplashView alloc] initWithFrame:self.window.bounds];
        [self.window addSubview:splashView];
        self.splashView = splashView;
    }
    - (void)applicationDidBecomeActive:(UIApplication *)application {
        // remove the splash view
        if (self.splashView) {
            [self.splashView removeFromSuperview];
            self.splashView = nil;
        }
    }
    @end
    
    0 讨论(0)
提交回复
热议问题