diff --git a/uni_modules/uni-usercapturescreen/utssdk/interface.uts b/uni_modules/uni-usercapturescreen/utssdk/interface.uts index 528ebb0045848b7eaec3fbff975d75243fbe25ff..dd803825df81de0c8719e5dc8b97daf59880c6cc 100644 --- a/uni_modules/uni-usercapturescreen/utssdk/interface.uts +++ b/uni_modules/uni-usercapturescreen/utssdk/interface.uts @@ -16,7 +16,7 @@ export type OnUserCaptureScreenResult = { /** * 截屏文件路径(仅Android返回) */ - path ?: string + path : string | null } export type UserCaptureScreenCallback = (res: OnUserCaptureScreenResult) => void diff --git a/uni_modules/uts-screenshot-listener/utssdk/app-ios/index.uts b/uni_modules/uts-screenshot-listener/utssdk/app-ios/index.uts index a1d2abec3d34e4040b42552341901dea3863fb2c..f4d6fc28d52c711bc5cbcf02b0381f10f0ce3848 100644 --- a/uni_modules/uts-screenshot-listener/utssdk/app-ios/index.uts +++ b/uni_modules/uts-screenshot-listener/utssdk/app-ios/index.uts @@ -1,14 +1,15 @@ 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) { - CaptureScreenTool.listenCaptureScreen(callback) +/** + * 开启截图监听 + */ +export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) { + CaptureScreenTool.listenCaptureScreen(callback) +} + +/** + * 关闭截屏监听 + */ +export const offUserCaptureScreen : OffUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) { + CaptureScreenTool.removeListen(callback) } -/** - * 关闭截屏监听 - */ -export function offUserCaptureScreen(callback?: UTSCallback) { - CaptureScreenTool.removeListen(callback) -} diff --git a/uni_modules/uts-screenshot-listener/utssdk/interface.uts b/uni_modules/uts-screenshot-listener/utssdk/interface.uts new file mode 100644 index 0000000000000000000000000000000000000000..dd803825df81de0c8719e5dc8b97daf59880c6cc --- /dev/null +++ b/uni_modules/uts-screenshot-listener/utssdk/interface.uts @@ -0,0 +1,42 @@ +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