From 6a772945e99a339ac366c310ec86716631176c4f Mon Sep 17 00:00:00 2001 From: XHY Date: Wed, 15 Mar 2023 15:29:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96iOS=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uni-getbatteryinfo/utssdk/app-ios/index.uts | 2 -- .../uni-memorywarning/utssdk/app-ios/index.uts | 15 +++++++++------ .../uni-memorywarning/utssdk/interface.uts | 6 ++++++ 3 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 uni_modules/uni-memorywarning/utssdk/interface.uts diff --git a/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts b/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts index 8813af8..755250f 100644 --- a/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts +++ b/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts @@ -14,8 +14,6 @@ export const getBatteryInfo : GetBatteryInfo = function (options) { // 返回数据 const res : GetBatteryInfoSuccess = { - errCode: 0, - errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: new Int(UIDevice.current.batteryLevel * 100), isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging, diff --git a/uni_modules/uni-memorywarning/utssdk/app-ios/index.uts b/uni_modules/uni-memorywarning/utssdk/app-ios/index.uts index e4dc943..97ef23d 100644 --- a/uni_modules/uni-memorywarning/utssdk/app-ios/index.uts +++ b/uni_modules/uni-memorywarning/utssdk/app-ios/index.uts @@ -2,11 +2,13 @@ import { NotificationCenter } from 'Foundation'; import { UIApplication } from "UIKit" import { Selector } from "ObjectiveC" +import { OffMemoryWarning, OnMemoryWarning, OnMemoryWarningCallback, OnMemoryWarningCallbackResult } from "../interface.uts" + class MemoryWarningTool { - static listeners: UTSCallback[] = [] + static listeners: OnMemoryWarningCallback[] = [] // 监听内存警告 - static listenMemoryWarning(callback: UTSCallback) { + static listenMemoryWarning(callback: OnMemoryWarningCallback) { // 只有首次才需要注册监听事件 if (this.listeners.length == 0) { @@ -23,12 +25,13 @@ class MemoryWarningTool { @objc static receiveMemoryWarning() { // 触发回调 this.listeners.forEach(listener => { - listener({}) + const ret: OnMemoryWarningCallbackResult = {} + listener(ret) }) } // 移除监听事件 - static removeListen(callback: UTSCallback | null) { + static removeListen(callback: OnMemoryWarningCallback | null) { // 移除所有监听 if (callback == null) { this.listeners = [] @@ -46,11 +49,11 @@ class MemoryWarningTool { } // 开启监听内存警告 -export function onMemoryWarning(callback: UTSCallback) { +export const onMemoryWarning : OnMemoryWarning = function (callback: OnMemoryWarningCallback) { MemoryWarningTool.listenMemoryWarning(callback) } // 关闭监听内存警告 -export function offMemoryWarning(callback: UTSCallback | null) { +export const offMemoryWarning : OffMemoryWarning = function (callback: OnMemoryWarningCallback | null) { MemoryWarningTool.removeListen(callback) } \ No newline at end of file diff --git a/uni_modules/uni-memorywarning/utssdk/interface.uts b/uni_modules/uni-memorywarning/utssdk/interface.uts new file mode 100644 index 0000000..b3a8615 --- /dev/null +++ b/uni_modules/uni-memorywarning/utssdk/interface.uts @@ -0,0 +1,6 @@ +export type OnMemoryWarningCallbackResult = { + level : number | null +} +export type OnMemoryWarningCallback = (res : OnMemoryWarningCallbackResult) => void +export type OnMemoryWarning = (callback : OnMemoryWarningCallback) => void +export type OffMemoryWarning = (callback : OnMemoryWarningCallback | null) => void \ No newline at end of file -- GitLab