diff --git a/uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts b/uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts index 1151d9e520c6da0284812eac14f2147aa243919f..68e7ad4651ea5abfe0f93cca85222e0d61d14f1e 100644 --- a/uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts +++ b/uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts @@ -1,14 +1,16 @@ import { NotificationCenter} from 'Foundation'; import { UIApplication } from "UIKit" +import { OnUserCaptureScreen, OffUserCaptureScreen, UserCaptureScreenCallback } from "../interface.uts" + /** * 定义监听截屏事件工具类 */ class CaptureScreenTool { - static listener?: UTSCallback; + static listener: UserCaptureScreenCallback | null; // 监听截屏 - static listenCaptureScreen(callback?: UTSCallback) { + static listenCaptureScreen(callback: UserCaptureScreenCallback | null) { this.listener = callback // 注册监听截屏事件及回调方法 @@ -20,30 +22,41 @@ class CaptureScreenTool { // 捕获截屏回调的方法 // target-action 的方法前需要添加 @objc 前缀 @objc static userDidTakeScreenshot() { - const obj = new UTSJSONObject() // 回调 - this.listener?.(obj) + this.listener?.({}) } // 移除监听事件 - static removeListen(callback?: UTSCallback) { + static removeListen(callback: UserCaptureScreenCallback | null) { this.listener = null NotificationCenter.default.removeObserver(this) - const obj = new UTSJSONObject() - callback?.(obj) } } -/** - * 开启截图监听 - */ -export function onUserCaptureScreen(callback?: UTSCallback) { - CaptureScreenTool.listenCaptureScreen(callback) -} +// /** +// * 开启截图监听 +// */ +// export function onUserCaptureScreen(callback?: UTSCallback) { +// CaptureScreenTool.listenCaptureScreen(callback) +// } -/** - * 关闭截屏监听 - */ -export function offUserCaptureScreen(callback?: UTSCallback) { - CaptureScreenTool.removeListen(callback) +// /** +// * 关闭截屏监听 +// */ +// export function offUserCaptureScreen(callback?: UTSCallback) { +// CaptureScreenTool.removeListen(callback) +// } + +/** + * 开启截图监听 + */ +export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) { + CaptureScreenTool.listenCaptureScreen(callback) +} + +/** + * 关闭截屏监听 + */ +export const offUserCaptureScreen : OffUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) { + CaptureScreenTool.removeListen(callback) } diff --git a/uni_modules/uni-usercapturescreen/utssdk/interface.uts b/uni_modules/uni-usercapturescreen/utssdk/interface.uts new file mode 100644 index 0000000000000000000000000000000000000000..6ed4533258c63d805e19ad884c964bf056586cda --- /dev/null +++ b/uni_modules/uni-usercapturescreen/utssdk/interface.uts @@ -0,0 +1,21 @@ +export type UserCaptureScreenCallback = (res: any) => 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 diff --git a/uni_modules/uts-syntaxcase/index.uts b/uni_modules/uts-syntaxcase/index.uts index 7d4948620b6de812b5368bc6852af9ddbc50696b..1a86e8254362be5e9c0290adb5c95557dc00c5ee 100644 --- a/uni_modules/uts-syntaxcase/index.uts +++ b/uni_modules/uts-syntaxcase/index.uts @@ -4,6 +4,16 @@ type AsyncOptions = { fail: (res: string) => void; complete: (res: string) => void; }; + +type SyntaxResult = { + name: string +}; + +type SyncResult = { + msg: string +} + + /** * 导出一个属性 */ @@ -13,11 +23,12 @@ export const MAX = 100; * 导出一个同步方法 * @returns */ -export function testSync(msg: string) { +export function testSync(msg: string): SyncResult { console.log("log test"); - return { - msg: `hello ${msg}`, - }; + const res: SyncResult = { + msg: `hello ${msg}` + } + return res } /** * 导出一个同步方法(触发了数组越界异常) @@ -37,20 +48,28 @@ export function testSyncWithCallback(opts: AsyncOptions) { opts.fail("fail"); } opts.complete("complete"); - return { name: "testSyncWithCallback" }; + + const res: SyntaxResult = { + name: "testSyncWithCallback" + } + return res } /** * 导出一个异步方法 * @returns */ -export async function testAsync(opts: AsyncOptions) { +export async function testAsync(opts: AsyncOptions): Promise { if (opts.type == "success") { opts.success("success"); } else { opts.fail("fail"); } opts.complete("complete"); - return { name: "testAsync" }; + + const res: SyntaxResult = { + name: "testAsync" + } + return res } type TestOptions = { @@ -67,17 +86,17 @@ export class Test { this.name = options.name; options.callback("Test.constructor"); } - static testClassStaticSyncWithCallback(opts: AsyncOptions): UTSJSONObject { + static testClassStaticSyncWithCallback(opts: AsyncOptions): SyntaxResult { return testSyncWithCallback(opts); } - static async testClassStaticAsync(opts: AsyncOptions): Promise { + static async testClassStaticAsync(opts: AsyncOptions): Promise { const res = await testAsync(opts); return res; } - testClassSyncWithCallback(opts: AsyncOptions): UTSJSONObject { + testClassSyncWithCallback(opts: AsyncOptions): SyntaxResult { return testSyncWithCallback(opts); } - async testClassAsync(opts: AsyncOptions): Promise { + async testClassAsync(opts: AsyncOptions): Promise { const res = await testAsync(opts); return res; } diff --git a/uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts b/uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts index dfdc29f8af3cb7ca3c092ba0217f686a99b3e8eb..ae77730d9c8fecf847c4e4993bd006de98ce712d 100644 --- a/uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts +++ b/uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts @@ -5,6 +5,15 @@ type AsyncOptions = { fail: (res: string) => void; complete: (res: string) => void; }; + +type SyntaxResult = { + name: string +}; + +type SyncResult = { + msg: string +} + /** * 导出一个属性 */ @@ -14,12 +23,17 @@ export const MAX = 100; * 导出一个同步方法 * @returns */ -export function testSync(msg: string) { +export function testSync(msg: string): SyncResult { console.log("log test"); log("log test1"); - return { - msg: `hello ${msg}`, - }; + + const res: SyncResult = { + msg: `hello ${msg}` + } + return res + // return { + // msg: `hello ${msg}`, + // }; } /** * 导出一个同步方法(触发了数组越界异常) @@ -32,27 +46,37 @@ export function testSyncError() { * 导出一个带callback的同步方法 * @param opts */ -export function testSyncWithCallback(opts: AsyncOptions) { +export function testSyncWithCallback(opts: AsyncOptions): SyntaxResult { if (opts.type == "success") { opts.success("success"); } else { opts.fail("fail"); } opts.complete("complete"); - return { name: "testSyncWithCallback" }; + + const res: SyntaxResult = { + name: "testSyncWithCallback" + } + return res; + // return { name: "testSyncWithCallback" }; } /** * 导出一个异步方法 * @returns */ -export async function testAsync(opts: AsyncOptions) { +export async function testAsync(opts: AsyncOptions): Promise { if (opts.type == "success") { opts.success("success"); } else { opts.fail("fail"); } opts.complete("complete"); - return { name: "testAsync" }; + + const res: SyntaxResult = { + name: "testAsync" + } + return res; + // return { name: "testAsync" }; } type TestOptions = { @@ -69,17 +93,17 @@ export class Test { this.name = options.name; options.callback("Test.constructor"); } - static testClassStaticSyncWithCallback(opts: AsyncOptions): UTSJSONObject { + static testClassStaticSyncWithCallback(opts: AsyncOptions): SyntaxResult { return testSyncWithCallback(opts); } - static async testClassStaticAsync(opts: AsyncOptions): Promise { + static async testClassStaticAsync(opts: AsyncOptions): Promise { const res = await testAsync(opts); return res; } - testClassSyncWithCallback(opts: AsyncOptions): UTSJSONObject { + testClassSyncWithCallback(opts: AsyncOptions): SyntaxResult { return testSyncWithCallback(opts); } - async testClassAsync(opts: AsyncOptions): Promise { + async testClassAsync(opts: AsyncOptions): Promise { const res = await testAsync(opts); return res; }