Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
8c02fe28
U
uni-api
项目概览
DCloud
/
uni-api
通知
655
Star
22
Fork
12
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8c02fe28
编写于
3月 15, 2023
作者:
lizhongyi_
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
uni-usercapturescreen 插件iOS调整
上级
a2acc722
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
61 addition
and
45 deletion
+61
-45
uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts
uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts
+57
-43
uni_modules/uni-usercapturescreen/utssdk/interface.uts
uni_modules/uni-usercapturescreen/utssdk/interface.uts
+4
-2
未找到文件。
uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts
浏览文件 @
8c02fe28
import { NotificationCenter } from 'Foundation';
import { CGRect } from "CoreFoundation";
import { UIApplication, UIView, UITextField, UIScreen, UIDevice } from "UIKit"
import { UTSiOS
, UTSCallback
} from "DCloudUTSFoundation"
import { UTSiOS } from "DCloudUTSFoundation"
import { DispatchQueue } from 'Dispatch';
import { SetUserCaptureScreenOption
, UserCaptureScreenResult, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreen
} from "../interface.uts"
import { SetUserCaptureScreenOption
s, UserCaptureScreenResult, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreen, UserCaptureScreenCallback, OnUserCaptureScreenResult
} from "../interface.uts"
/**
* 定义监听截屏事件工具类
*/
class CaptureScreenTool {
static listener
?: UTSCallback
;
static secureView
?: UIView
;
static listener
: UserCaptureScreenCallback | null
;
static secureView
: UIView | null
;
// 监听截屏
static listenCaptureScreen(callback
?: UTSCallback
) {
static listenCaptureScreen(callback
: UserCaptureScreenCallback | null
) {
this.listener = callback
// 注册监听截屏事件及回调方法
...
...
@@ -26,34 +26,44 @@ class CaptureScreenTool {
// target-action 的方法前需要添加 @objc 前缀
@objc static userDidTakeScreenshot() {
// 回调
this.listener?.({})
const res: OnUserCaptureScreenResult = {
errCode: 0,
errSubject: "uni-usercapturescreen",
errMsg: "onUserCaptureScreen: ok",
path: null
}
this.listener?.(res)
}
// 移除监听事件
static removeListen(callback
?: UTSCallback
) {
static removeListen(callback
: UserCaptureScreenCallback | null
) {
this.listener = null
NotificationCenter.default.removeObserver(this)
callback?.({})
const res: OnUserCaptureScreenResult = {
errCode: 0,
errSubject: "uni-usercapturescreen",
errMsg: "offUserCaptureScreen: ok",
path: null
}
callback?.(res)
}
static createSecureView() : UIView | null {
let field = new UITextField(frame = CGRect.zero)
field.isSecureTextEntry = true
if (field.subviews.count > 0 && UIDevice.current.systemVersion != '15.1') {
let view = field.subviews.first
if (view != null) {
view!.subviews.forEach((item) => {
if (field.subviews.length > 0 && UIDevice.current.systemVersion != '15.1') {
let view = field.subviews[0]
view.subviews.forEach((item) => {
item.removeFromSuperview()
})
view!.isUserInteractionEnabled = true
view.isUserInteractionEnabled = true
return view
}
}
return null
}
// 开启防截屏
static onAntiScreenshot(option : SetUserCaptureScreenOption) {
static onAntiScreenshot(option : SetUserCaptureScreenOption
s
) {
// uts方法默认会在子线程中执行,涉及 UI 操作必须在主线程中运行,通过 DispatchQueue.main.async 方法可将代码在主线程中运行
DispatchQueue.main.async(execute = () : void => {
let secureView = this.createSecureView()
...
...
@@ -71,17 +81,18 @@ class CaptureScreenTool {
rootView!.frame = rect
}
}
let res = new UserCaptureScreenResult()
res.errCode = 0;
res.errSubject = "uni-usercapturescreen";
res.errMsg = "setUserCaptureScreen:ok";
let res: UserCaptureScreenResult = {
errCode: 0,
errSubject: "uni-usercapturescreen",
errMsg: "setUserCaptureScreen:ok"
}
option.success?.(res)
option.complete?.(res)
})
}
// 关闭防截屏
static offAntiScreenshot(option : SetUserCaptureScreenOption) {
static offAntiScreenshot(option : SetUserCaptureScreenOption
s
) {
DispatchQueue.main.async(execute = () : void => {
if (this.secureView != null) {
let window = UTSiOS.getKeyWindow()
...
...
@@ -95,10 +106,11 @@ class CaptureScreenTool {
}
this.secureView = null
}
let res = new UserCaptureScreenResult()
res.errCode = 0;
res.errSubject = "uni-usercapturescreen";
res.errMsg = "setUserCaptureScreen:ok";
let res: UserCaptureScreenResult = {
errCode: 0,
errSubject: "uni-usercapturescreen",
errMsg: "setUserCaptureScreen:ok"
}
option.success?.(res)
option.complete?.(res)
})
...
...
@@ -108,34 +120,36 @@ class CaptureScreenTool {
/**
* 开启截图监听
*/
export const onUserCaptureScreen : OnUserCaptureScreen = function (callback
?: UTSCallback
) {
export const onUserCaptureScreen : OnUserCaptureScreen = function (callback
: UserCaptureScreenCallback | null
) {
CaptureScreenTool.listenCaptureScreen(callback)
}
/**
* 关闭截屏监听
*/
export const offUserCaptureScreen : OffUserCaptureScreen = function (callback
?: UTSCallback
) {
export const offUserCaptureScreen : OffUserCaptureScreen = function (callback
: UserCaptureScreenCallback | null
) {
CaptureScreenTool.removeListen(callback)
}
/**
* 开启/关闭防截屏
*/
export const setUserCaptureScreen : SetUserCaptureScreen = function (options : SetUserCaptureScreenOption) {
export const setUserCaptureScreen : SetUserCaptureScreen = function (options : SetUserCaptureScreenOption
s
) {
if (UIDevice.current.systemVersion < "13.0") {
let res = new UserCaptureScreenResult()
res.errCode = 12001;
res.errSubject = "uni-usercapturescreen";
res.errMsg = "setUserCaptureScreen:system not support";
let res: UserCaptureScreenResult = {
errCode: 12001,
errSubject: "uni-usercapturescreen",
errMsg: "setUserCaptureScreen:system not support"
}
options.fail?.(res);
options.complete?.(res);
} else if (UIDevice.current.systemVersion == "15.1") {
let res = new UserCaptureScreenResult()
res.errCode = 12010;
res.errSubject = "uni-usercapturescreen";
res.errMsg = "setUserCaptureScreen:system internal error";
let res: UserCaptureScreenResult = {
errCode: 12010,
errSubject: "uni-usercapturescreen",
errMsg: "setUserCaptureScreen:system internal error"
}
options.fail?.(res);
options.complete?.(res);
} else {
...
...
uni_modules/uni-usercapturescreen/utssdk/interface.uts
浏览文件 @
8c02fe28
...
...
@@ -2,6 +2,7 @@ export type UserCaptureScreenResult = {
/**
* 错误码
* 0:成功
* -1:permission denied
* 12001:system not support
* 12010:system internal error
*/
...
...
@@ -81,7 +82,7 @@ export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null)
/**
* 设置防截屏
*
* @param {SetUserCaptureScreenOption} options
* @param {SetUserCaptureScreenOption
s
} options
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.7.3
...
...
@@ -93,3 +94,4 @@ interface uni {
offUserCaptureScreen : OffUserCaptureScreen,
setUserCaptureScreen : SetUserCaptureScreen
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录