ios - 如何了解 IOS 11 中是否正在录制设备屏幕
<p><p>我的应用程序包含受版权保护的内容。我不希望用户记录它。如果他们开始录制屏幕,我希望我的应用程序能够捕捉到这一点。录屏时要捕捉什么功能?</p>
<p>我不想阻止,我想了解并捕获它。</p>
<p>注意:一些答案表明解决方案包括 AirPlay 和镜像。我想要的是只捕获在应用程序之前或期间开始的屏幕录制。我想允许用户使用 AirPlay 和 Mirroring。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><strong>SWIFT 5.0</strong></p>
<p>为了防止屏幕录制,我创建了一个单独的类 <code>ScreenRecordingProtoector</code></p>
<p>女巫长这样:</p>
<pre><code>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)
}
}
</code></pre>
<p>然后我只需在 <code>didFinishLaunchingWithOptions</code> <code>let screenRecordingProtoector = ScreenRecordingProtoector()</code> 上方的 AppDelegate 中创建一个变量,然后我在 <code>didFinishLaunchingWithOptions</code> <code>screenRecordingProtoector 内部调用.startPreventing()</code></p>
<pre><code>class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
private let preventService = PreventCapturingService()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: ?) -> Bool {
preventService.startPreventScreenRecording()
return true
}
}
</code></pre>
<p>它在 Swift 5.0 中对我来说很好用</p></p>
<p style="font-size: 20px;">关于ios - 如何了解 IOS 11 中是否正在录制设备屏幕,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/46217459/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/46217459/
</a>
</p>
页:
[1]