iOS 防截图和防录屏通用库

SYPreventScreenshot

项目地址:https://github.com/SyNvNX/SYPreventScreenshot/

一个用来防截图和防录屏的通用库,支持 ImageView 和 Label。

效果

防截图

第一个效果图实际上是支持防录屏,效果图为了展示效果,禁止了防录屏的功能。

防录屏

介绍

本库通过 DRM (Digital Rights Management,数字版权管理) 和 preventsCapture 特性支持了 >= iOS 10 系统的防截图功能。如果模拟器不生效,请使用真机。
本库的实现没有使用 UITextField 的 secureTextEntry 特性实现防截图,因为其使用到了私有类,在各个系统版本兼容性差,目前已经知道在 iOS 10,11,12,16.7.8,18 等系统版本不支持,在 iOS 15.0.2,16.2 等多个版本存异常问题,可能有更多不同版本有异常,但无法一一验证。

如何使用

  • Objective-C
#import <SYPreventScreenshot/SYPreventScreenshot.h>

UIImage *image = [UIImage imageNamed:@"image"];
SYPreventScreenshotImageView *imageView = [[SYPreventScreenshotImageView alloc] initWithImage:image];
[self.view addSubview:imageView];
    
SYPreventScreenshotLabel *label = [[SYPreventScreenshotLabel alloc] initWithText:@"Hello, world!"];
[self.view addSubview:label];
  • Swift
import SYPreventScreenshot

let imageView = SYPreventScreenshotImageView(image: UIImage(named: "image"))
view.addSubview(imageView)
    
let label = SYPreventScreenshotLabel(text: "Hello, world!")
view.addSubview(label)

SDWebImage

  • Objective-C
#import <SYPreventScreenshot/SYPreventScreenshotImageView+WebCache.h>

SYPreventScreenshotImageView *imageView = [[SYPreventScreenshotImageView alloc] initWithImage:nil];
NSURL *URL = [NSURL URLWithString:@"http://www.domain.com/path/to/image.png"];
UIImage *placeholderImage = [UIImage imageNamed:@"image"];
[imageView sy_setImageWithURL:URL placeholderImage:placeholderImage];
  • Swift
import SYPreventScreenshot

let imageView = SYPreventScreenshotImageView(image: nil)
let placeholderImage = UIImage(named: "image")
let `URL` = URL.init(string: "http://www.domain.com/path/to/image.png")
imageView.sy_setImage(with: `URL`, placeholderImage: placeholderImage)

安装

CocoaPods

Podfile 中添加以下代码:

pod 'SYPreventScreenshot'

# or 

pod 'SYPreventScreenshot/SDWebImage'

然后在终端运行以下命令:

$ pod install

基本要求

  • iOS 10.0+
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容