Prevent iOS from taking screen capture of app before going into background

后端 未结 10 2686
Happy的楠姐
Happy的楠姐 2020-11-29 22:35

You all might know that iOS takes a screen shot of your application before throwing it into the background. This is usually for a better User experience like quick animation

10条回答
  •  没有蜡笔的小新
    2020-11-29 23:13

    Apple Doc https://developer.apple.com/library/archive/qa/qa1838/_index.html

    Note: Your implementation of -applicationDidEnterBackground: should not start any animations (pass NO to any animated: parameter). The snapshot of your application's window is captured immediately upon returning from this method. Animations will not complete before the snapshot is taken.

    Converted Apple code in swift 4.2 App delegate i declared

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Your application can present a full screen modal view controller to
        // cover its contents when it moves into the background. If your
        // application requires a password unlock when it retuns to the
        // foreground, present your lock screen or authentication view controller here.
    
        let blankViewController = UIViewController()
        blankViewController.view.backgroundColor = UIColor.black
    
        // Pass NO for the animated parameter. Any animation will not complete
        // before the snapshot is taken.
        window.rootViewController?.present(blankViewController, animated: false)
    }
    
    func applicationWillEnterForeground(_ application: UIApplication) {
        // This should be omitted if your application presented a lock screen
        // in -applicationDidEnterBackground:
        window.rootViewController?.dismiss(animated: false) false
    }
    

提交回复
热议问题