提交 40663c1e 编写于 作者: lizhongyi_'s avatar lizhongyi_

uts-screenshoot-listener 调整uts语法

上级 f2e12be8
......@@ -16,7 +16,7 @@ export type OnUserCaptureScreenResult = {
/**
* 截屏文件路径(仅Android返回)
*/
path ?: string
path : string | null
}
export type UserCaptureScreenCallback = (res: OnUserCaptureScreenResult) => void
......
import { NotificationCenter} from 'Foundation';
import { UIApplication } from "UIKit"
import { OnUserCaptureScreen, OffUserCaptureScreen, UserCaptureScreenCallback, OnUserCaptureScreenResult } from "../interface.uts"
/**
* 定义监听截屏事件工具类
*/
class CaptureScreenTool {
static listener?: UTSCallback;
static listener: UserCaptureScreenCallback | null;
// 监听截屏
static listenCaptureScreen(callback?: UTSCallback) {
static listenCaptureScreen(callback: UserCaptureScreenCallback | null) {
this.listener = callback
// 注册监听截屏事件及回调方法
......@@ -21,27 +22,40 @@ 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)
}
}
/**
* 开启截图监听
*/
export function onUserCaptureScreen(callback?: UTSCallback) {
export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) {
CaptureScreenTool.listenCaptureScreen(callback)
}
/**
* 关闭截屏监听
*/
export function offUserCaptureScreen(callback?: UTSCallback) {
export const offUserCaptureScreen : OffUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) {
CaptureScreenTool.removeListen(callback)
}
export type OnUserCaptureScreenResult = {
/**
* 错误码
* 0:成功
* -1:permission denied
*/
errCode : number,
/**
* 调用API的名称
*/
errSubject : string,
/**
* 错误的详细信息
*/
errMsg : string,
/**
* 截屏文件路径(仅Android返回)
*/
path : string | null
}
export type UserCaptureScreenCallback = (res: OnUserCaptureScreenResult) => 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 : UserCaptureScreenCallback | null) => 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 : UserCaptureScreenCallback | null) => void
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册