如何了解 iOS 11 中设备屏幕是否正在录制

bir*_*age 3 objective-c ios ios11

我有一个具有受版权保护的内容的应用程序。我不希望用户记录它。如果他们开始录制屏幕,我希望我的应用程序能够捕捉到这一点。如果正在录屏,用什么函数来捕捉?

我不想阻止,我想理解并抓住它。

注意:一些答案表示解决方案包括 AirPlay 和镜像。我想要的是只捕获在应用程序之前或期间开始的屏幕录制。我想允许用户使用 AirPlay 和 Mirroring。

Pit*_*Pan 5

环球银行金融电信协会5.0

为了防止屏幕录制,我创建了一个单独的类ScreenRecordingProtoector

女巫看起来像这样:

final class ScreenRecordingProtoector {

private var window: UIWindow? {
    if #available(iOS 13.0, *) {
        return (UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.window
    }
    return (UIApplication.shared.delegate as? AppDelegate)?.window
}

func startPreventing() {
    NotificationCenter.default.addObserver(self, selector: #selector(preventScreenShoot), name: UIScreen.capturedDidChangeNotification, object: nil)
}

@objc private func preventScreenShoot() {
    if #available(iOS 13.0, *) {
        if UIScreen.main.isCaptured {
            window?.isHidden = true
        } else {
            window?.isHidden = false
        }
    }
}

// MARK: - Deinit
deinit {
    NotificationCenter.default.removeObserver(self)
}
}
Run Code Online (Sandbox Code Playgroud)

然后我只需在上面的 AppDelegate 中创建一个变量didFinishLaunchingWithOptions let screenRecordingProtoector = ScreenRecordingProtoector(),然后在里面调用didFinishLaunchingWithOptions screenRecordingProtoector.startPreventing()

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
private let preventService = PreventCapturingService()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    preventService.startPreventScreenRecording()

    return true
}
}
Run Code Online (Sandbox Code Playgroud)

它在 Swift 5.0 中对我来说工作得很好