Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
c7bdfe11
U
uni-api
项目概览
DCloud
/
uni-api
通知
690
Star
23
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看板
提交
c7bdfe11
编写于
3月 01, 2023
作者:
lizhongyi_
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
补充uni-usercapturescreen插件interface.uts
上级
5f97b8a7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
295 addition
and
247 deletion
+295
-247
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
+75
-83
uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts
uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts
+147
-164
uni_modules/uni-usercapturescreen/utssdk/interface.uts
uni_modules/uni-usercapturescreen/utssdk/interface.uts
+73
-0
未找到文件。
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
浏览文件 @
c7bdfe11
type GetBatteryInfoResult = {
/**
* 错误码
*/
errCode: number,
/**
* 调用API的名称
*/
errSubject: string,
/**
* 错误的详细信息
*/
errMsg: string,
/**
* 设备电量,范围1 - 100
*/
level: number,
/**
* 是否正在充电中
*/
isCharging: boolean
}
interface UniError<T> {
/**
* 错误码
*/
errCode:T,
/**
* 调用API的名称
*/
errSubject:string,
/**
* 错误的详细信息
*/
errMsg:string,
/**
* 错误来源
*/
cause:any
}
/**
* 错误码
*/
type GetBatteryInfoErrorCode =
/** 成功 */
0
/** getAppContext is null */
| 1001
/** navigator.getBattery is unsupported */
| 1002
;
export type GetBatteryInfoOptions = {
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
success?: (res: GetBatteryInfoResult) => void
/**
* 接口调用失败的回调函数
*/
fail?: (res: UniError<GetBatteryInfoErrorCode>) => void
/**
* 接口调用成功的回调
*/
complete?: (res: object) => void
}
/**
* 获取电量信息
* @param {GetBatteryInfoOptions} options
*
*
* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.11
*
* @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false })
* @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" })
*/
export default function getBatteryInfo(options: GetBatteryInfoOptions): void
type GetBatteryInfoResult = {
/**
* 错误码
* 0:成功
* 1001:getAppContext is null
* 1002:navigator.getBattery is unsupported
*/
errCode : number,
/**
* 调用API的名称
*/
errSubject : string,
/**
* 错误的详细信息
*/
errMsg : string,
/**
* 设备电量,范围1 - 100
*/
level : number,
/**
* 是否正在充电中
*/
isCharging : boolean
}
interface UniError<T> {
/**
* 错误码
*/
errCode : number,
/**
* 调用API的名称
*/
errSubject : string,
/**
* 错误的详细信息
*/
errMsg : string,
/**
* 错误来源
*/
cause : any
}
export type GetBatteryInfoOptions = {
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
success ?: (res : GetBatteryInfoResult) => void
/**
* 接口调用失败的回调函数
*/
fail ?: (res : UniError) => void
/**
* 接口调用成功的回调
*/
complete ?: (res : object) => void
}
/**
* 获取电量信息
* @param {GetBatteryInfoOptions} options
*
*
* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.11
*
* @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false })
* @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" })
*/
export default function getBatteryInfo(options : GetBatteryInfoOptions) : void
uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts
浏览文件 @
c7bdfe11
import { NotificationCenter } from 'Foundation';
import { UIApplication, UIView, UITextField, UIScreen, UIDevice } from "UIKit"
import { UTSiOS } from "DCloudUTSFoundation"
import { DispatchQueue } from 'Dispatch';
import { NotificationCenter } from 'Foundation';
import { UIApplication, UIView, UITextField, UIScreen, UIDevice } from "UIKit"
import { UTSiOS, UTSCallback } from "DCloudUTSFoundation"
import { DispatchQueue } from 'Dispatch';
import { SetUserCaptureScreenOption, UserCaptureScreenResult, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreen } from "../interface.uts"
/**
* 定义监听截屏事件工具类
*/
class CaptureScreenTool {
static listener ?: UTSCallback;
static secureView ?: UIView;
// 监听截屏
static listenCaptureScreen(callback ?: UTSCallback) {
this.listener = callback
// 注册监听截屏事件及回调方法
// target-action 回调方法需要通过 Selector("方法名") 构建
const method = Selector("userDidTakeScreenshot")
NotificationCenter.default.addObserver(this, selector = method, name = UIApplication.userDidTakeScreenshotNotification, object = null)
}
// 捕获截屏回调的方法
// target-action 的方法前需要添加 @objc 前缀
@objc static userDidTakeScreenshot() {
// 回调
this.listener?.({})
}
// 移除监听事件
static removeListen(callback ?: UTSCallback) {
this.listener = null
NotificationCenter.default.removeObserver(this)
callback?.({})
}
static createSecureView() : UIView | null {
let field = UITextField()
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) => {
item.removeFromSuperview()
})
view!.isUserInteractionEnabled = true
return view
}
}
return null
}
// 开启防截屏
static onAntiScreenshot(option : SetUserCaptureScreenOption) {
// uts方法默认会在子线程中执行,涉及 UI 操作必须在主线程中运行,通过 DispatchQueue.main.async 方法可将代码在主线程中运行
DispatchQueue.main.async(execute = () : void => {
let secureView = this.createSecureView()
let window = UTSiOS.getKeyWindow()
let rootView = window.rootViewController == null ? null : window.rootViewController!.view
if (secureView != null && rootView != null) {
let rootSuperview = rootView!.superview
if (rootSuperview != null) {
this.secureView = secureView
rootSuperview!.addSubview(secureView!)
rootView!.removeFromSuperview()
secureView!.addSubview(rootView!)
let rect = rootView!.frame
secureView!.frame = UIScreen.main.bounds
rootView!.frame = rect
}
}
let res = new UserCaptureScreenResult()
res.errCode = 0;
res.errSubject = "uni-usercapturescreen";
res.errMsg = "setUserCaptureScreen:ok";
option.success?.(res)
option.complete?.(res)
})
}
// 关闭防截屏
static offAntiScreenshot(option : SetUserCaptureScreenOption) {
DispatchQueue.main.async(execute = () : void => {
if (this.secureView != null) {
let window = UTSiOS.getKeyWindow()
let rootView = window.rootViewController == null ? null : window.rootViewController!.view
if (rootView != null && this.secureView!.superview != null) {
let rootSuperview = this.secureView!.superview
if (rootSuperview != null) {
rootSuperview!.addSubview(rootView!)
this.secureView!.removeFromSuperview()
}
}
this.secureView = null
}
let res = new UserCaptureScreenResult()
res.errCode = 0;
res.errSubject = "uni-usercapturescreen";
res.errMsg = "setUserCaptureScreen:ok";
option.success?.(res)
option.complete?.(res)
})
}
}
/**
* 开启截图监听
*/
export const onUserCaptureScreen : OnUserCaptureScreen = function (callback ?: UTSCallback) {
CaptureScreenTool.listenCaptureScreen(callback)
}
/**
* 关闭截屏监听
*/
export const offUserCaptureScreen : OffUserCaptureScreen = function (callback ?: UTSCallback) {
CaptureScreenTool.removeListen(callback)
}
/**
* 开启/关闭防截屏
*/
export const setUserCaptureScreen : SetUserCaptureScreen = function (options : SetUserCaptureScreenOption) {
if (UIDevice.current.systemVersion < "13.0") {
let res = new UserCaptureScreenResult()
res.errCode = 12001;
res.errSubject = "uni-usercapturescreen";
res.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";
options.fail?.(res);
options.complete?.(res);
} else {
if (options.open == true) {
CaptureScreenTool.onAntiScreenshot(options)
} else {
CaptureScreenTool.offAntiScreenshot(options)
}
}
}
/**
* 设置防截屏options
*/
type SetUserCaptureScreenOption = {
open: boolean;
success?: (res: UTSJSONObject) => void;
fail?: (res: UTSJSONObject) => void;
complete?: (res: UTSJSONObject) => void;
}
/**
* 定义监听截屏事件工具类
*/
class CaptureScreenTool {
static listener?: UTSCallback;
static secureView?: UIView;
// 监听截屏
static listenCaptureScreen(callback?: UTSCallback) {
this.listener = callback
// 注册监听截屏事件及回调方法
// target-action 回调方法需要通过 Selector("方法名") 构建
const method = Selector("userDidTakeScreenshot")
NotificationCenter.default.addObserver(this, selector = method, name = UIApplication.userDidTakeScreenshotNotification, object = null)
}
// 捕获截屏回调的方法
// target-action 的方法前需要添加 @objc 前缀
@objc static userDidTakeScreenshot() {
// 回调
this.listener?.({})
}
// 移除监听事件
static removeListen(callback?: UTSCallback) {
this.listener = null
NotificationCenter.default.removeObserver(this)
callback?.({})
}
static createSecureView(): UIView | null {
let field = UITextField()
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) => {
item.removeFromSuperview()
})
view!.isUserInteractionEnabled = true
return view
}
}
return null
}
// 开启防截屏
static onAntiScreenshot(option: SetUserCaptureScreenOption) {
// uts方法默认会在子线程中执行,涉及 UI 操作必须在主线程中运行,通过 DispatchQueue.main.async 方法可将代码在主线程中运行
DispatchQueue.main.async(execute = (): void => {
let secureView = this.createSecureView()
let window = UTSiOS.getKeyWindow()
let rootView = window.rootViewController == null ? null : window.rootViewController!.view
if (secureView != null && rootView != null) {
let rootSuperview = rootView!.superview
if (rootSuperview != null) {
this.secureView = secureView
rootSuperview!.addSubview(secureView!)
rootView!.removeFromSuperview()
secureView!.addSubview(rootView!)
let rect = rootView!.frame
secureView!.frame = UIScreen.main.bounds
rootView!.frame = rect
}
}
let res = {
errSubject: "uts-screenshot-listener",
errCode: 0,
errMsg: "setUserCaptureScreen:ok",
}
option.success?.(res)
option.complete?.(res)
})
}
// 关闭防截屏
static offAntiScreenshot(option: SetUserCaptureScreenOption) {
DispatchQueue.main.async(execute = (): void => {
if (this.secureView != null) {
let window = UTSiOS.getKeyWindow()
let rootView = window.rootViewController == null ? null : window.rootViewController!.view
if (rootView != null && this.secureView!.superview != null) {
let rootSuperview = this.secureView!.superview
if (rootSuperview != null) {
rootSuperview!.addSubview(rootView!)
this.secureView!.removeFromSuperview()
}
}
this.secureView = null
}
let res = {
errSubject: "uts-screenshot-listener",
errCode: 0,
errMsg: "setUserCaptureScreen:ok",
}
option.success?.(res)
option.complete?.(res)
})
}
}
/**
* 开启截图监听
*/
export function onUserCaptureScreen(callback?: UTSCallback) {
CaptureScreenTool.listenCaptureScreen(callback)
}
/**
* 关闭截屏监听
*/
export function offUserCaptureScreen(callback?: UTSCallback) {
CaptureScreenTool.removeListen(callback)
}
/**
* 开启/关闭防截屏
*/
export function setUserCaptureScreen(option: SetUserCaptureScreenOption) {
if (UIDevice.current.systemVersion < "13.0") {
let res = {
errSubject: "uts-screenshot-listener",
errCode: 12001,
errMsg: "setUserCaptureScreen:system not support"
}
option.fail?.(res);
option.complete?.(res);
} else if (UIDevice.current.systemVersion == "15.1") {
let res = {
errSubject: "uts-screenshot-listener",
errCode: 12010,
errMsg: "setUserCaptureScreen:system internal error"
}
option.fail?.(res);
option.complete?.(res);
} else {
if (option.open == true) {
CaptureScreenTool.onAntiScreenshot(option)
} else {
CaptureScreenTool.offAntiScreenshot(option)
}
}
}
\ No newline at end of file
uni_modules/uni-usercapturescreen/utssdk/interface.uts
0 → 100644
浏览文件 @
c7bdfe11
export type UserCaptureScreenResult = {
/**
* 错误码
* 0:成功
* 12001:system not support
* 12010:system internal error
*/
errCode : number,
/**
* 调用API的名称
*/
errSubject : string,
/**
* 错误的详细信息
*/
errMsg : string,
}
export type SetUserCaptureScreenOption = {
/**
* true: 开启防截屏 false: 关闭防截屏
*/
open : boolean;
/**
* 接口调用成功的回调函数
*/
success ?: (res : UserCaptureScreenResult) => void,
/**
* 接口调用失败的回调函数
*/
fail ?: (res : UserCaptureScreenResult) => void,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete ?: (res : UserCaptureScreenResult) => void
}
/**
* 开启截屏监听
*
* @param {UTSCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.8
*/
export type OnUserCaptureScreen = (callback ?: UTSCallback) => void
/**
* 关闭截屏监听
*
* @param {UTSCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.8
*/
export type OffUserCaptureScreen = (callback ?: UTSCallback) => void
/**
* 设置防截屏
*
* @param {SetUserCaptureScreenOption} 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
*/
export type SetUserCaptureScreen = (options : SetUserCaptureScreenOption) => void
interface uni {
onUserCaptureScreen : OnUserCaptureScreen,
offUserCaptureScreen : OffUserCaptureScreen,
setUserCaptureScreen : SetUserCaptureScreen
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录