iOS 防截屏/录屏 方案

防君子,不防小人😌

iOS13 及以上用的UITextField,系统会自动屏蔽截屏录屏,录屏时不影响视频体验。(录屏结果是全白屏,有声音)

iOS12 使用的监听录制通知,隐藏了直播的播放器,录屏时整个屏幕黑掉了(影响视频体验)(录屏结果全黑屏,有声音,视频前一两帧有内容,应该是系统回调延迟)

ScreenShieldView 参考 Swifty/ScreenShieldView.swift at master · RyukieSama/Swifty

// MARK: Life Cycle
    public override func loadView() {
        if #available(iOS 13.0, *) {
            view = ScreenShieldView.create()
        }
        else {
            super.loadView()
            NotificationCenter.default.addObserver(self, selector: #selector(tipsVideoRecord), name: UIScreen.capturedDidChangeNotification, object: nil)
        }
    }

    // MARK: Screen Shield iOS12
    @objc private func tipsVideoRecord(){
        let sc = UIScreen.main
        if sc.isCaptured {
            //  video view hidden ture
        }else{
            // video view hidden false
        }
    }

参考