[英]How to prevent iOS11 Built in screen recording feature just like Amazon Prime for protected DRM content?
[英]How to check iOS11 Screen Recording is On or Off?
为了检测 iOS11 屏幕录制功能的开或关,我使用了 isCaptured 和 UIScreenCapturedDidChange Notification。
当我第一次启动应用程序并在 iOS11 内置屏幕录制功能上时,它会用值 True 通知选择器方法,但是当我杀死(终止)正在运行的应用程序并再次启动应用程序时,再次执行相同的程序,然后我的选择器方法是没有被调用。
这是我的代码:
我在 ViewWillAppear() 方法中添加了一个观察者:
NotificationCenter.default.addObserver(self, selector: #selector(handleNotification), name: NSNotification.Name.UIScreenCapturedDidChange, object: nil)
选择器方法如下:
@objc
func handleNotification(notification:Notification){
let isCaptured = UIScreen.main.isCaptured
print("isCaptured value = \(isCaptured)")
}
在这种情况下,我需要终止该应用程序,清除缓存并再次启动该应用程序以获取屏幕录制事件。
请建议我可以在这里做些什么来检测录制事件以保护我的内容不被录制。
斯威夫特 4
添加观察者
UIScreen.main.addObserver(self, forKeyPath: "captured", options: .new, context: nil)
接收更改
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
if (keyPath == "captured") {
let isCaptured = UIScreen.main.isCaptured
print(isCaptured)
}
}
我想无论通知如何,您都可以始终检查此变量
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let isCaptured = UIScreen.main.isCaptured
return true
}
该功能适用于 iOS11 及以上版本。 最好把它放在didFinishLaunchingWithOptions里面
Objective-C 语法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
if (@available(iOS 11.0, *)) {
BOOL isCaptured = [[UIScreen mainScreen] isCaptured];
if(isCaptured){
// Do the action for hiding the screen recording
}
} else{
// Fallback on earlier versions
}
return YES;
}
@UmeshKumath 当杀死应用程序清除缓存并再次启动应用程序以获取屏幕录制事件时,这很容易,您需要在 viewdidload 中运行代码,如下所示:
override func viewDidLoad() {
super.viewDidLoad()
UIScreen.main.addObserver(self, forKeyPath: "some key", options: .new, context: nil)
let isCaptured = UIScreen.main.isCaptured
if isCaptured == true {
// do something
}
这是检测是否已截取屏幕截图的方法
func detectScreenShot(action: @escaping () -> ()) {
let mainQueue = OperationQueue.main
NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: mainQueue) { notification in
// executes after screenshot
action()
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.