How to disable screen Recording in iOS app
Asked Answered
A

4

8

Is there any way to disable the screen recording? or is is possible through a configuration profile? or any third party library is available?

Argol answered 21/12, 2018 at 7:1 Comment(4)
@PyaePhyoeShein without using blockView any solution?..Argol
how about self.view.backgroundColor = UIColor.red or something else?Pastiche
without interrupted my app user experience. only my app can avoid screen recordding ??.Argol
show overlay popup with warning is the best.Pastiche
P
12
NotificationCenter.default.addObserver(self, selector: #selector(preventScreenRecording), name: NSNotification.Name.UIScreenCapturedDidChange, object: nil)

And create a view inside main view and prevent like that.

(void) preventScreenRecording {
if (@available(iOS 11.0, *)) {
    BOOL isCaptured = [[UIScreen mainScreen] isCaptured];

    if (isCaptured) {
        self.blockView.hidden = false;
    }
    else {
        self.blockView.hidden = true;
    }
}
Pastiche answered 21/12, 2018 at 7:16 Comment(6)
Can you explain what is blockView here? And I believe this method is called after screenshot is captured. I haven't tested it yetArbitral
@Pastiche is there any way to disable screenshot?Oversew
@Arbitral blockView is the area that you want to disable screenRecording.Pastiche
@SagarDaundkar I think it would be same as what I mentioned.Pastiche
could you please write as full code? thanksDap
Pls see https://mcmap.net/q/1186111/-ios-11-prevent-screen-record-like-netflix, having complete code.Levine
S
4

When your app is started you can test UIScreen.isCaptured property and show some splash screen if it's set to true.

You should also observe (subscribe in some place for) capturedDidChangeNotification notification, and do same thing (show splash screen) if UIScreen.isCaptured is set to true.

Sprightly answered 21/12, 2018 at 7:17 Comment(1)
I am able to detect screen recoding using UIScreen.isCaptured.how to avoid screen recoding in my app without interrupted user experience of my app.Argol
L
2

Swift 4 and above

You just need to make the following changes in your Appdelegate.swift page.

It will automatically add a blurred view on the top of the app when the user tries to record the screen.

weak var screen : UIView? = nil

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    NotificationCenter.default.addObserver(self, selector: #selector(preventScreenRecording), name: UIScreen.capturedDidChangeNotification, object: nil)
    return true
}

@objc func preventScreenRecording() {
    let isCaptured = UIScreen.main.isCaptured
    print("isCaptured: \(isCaptured)")
    if isCaptured {
        blurScreen()
    }
    else {
        removeBlurScreen()
    }
}

func blurScreen(style: UIBlurEffect.Style = UIBlurEffect.Style.regular) {
    screen = UIScreen.main.snapshotView(afterScreenUpdates: false)
    let blurEffect = UIBlurEffect(style: style)
    let blurBackground = UIVisualEffectView(effect: blurEffect)
    screen?.addSubview(blurBackground)
    blurBackground.frame = (screen?.frame)!
    window?.addSubview(screen!)
}

func removeBlurScreen() {
    screen?.removeFromSuperview()
}
Levine answered 18/2, 2022 at 9:25 Comment(0)
P
1
sharedRecorder.stopRecording( handler: { previewViewController, error in    
    if let error = error {
        print("\(error.localizedDescription)")
    }
    if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad {
        previewViewController?.modalPresentationStyle = UIModalPresentationStyle.popover
        previewViewController?.popoverPresentationController?.sourceRect = CGRect.zero
        previewViewController?.popoverPresentationController?.sourceView = self.view
    }
    if previewViewController != nil {
        self.previewViewController = previewViewController
        previewViewController?.previewControllerDelegate = self
    }
    self.present(previewViewController!, animated: true, completion: nil)
    })
    return
}



https://developer.apple.com/documentation/replaykit/rpscreenrecorder/1620990-stoprecording
Preeminent answered 21/12, 2018 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.