diff --git a/.gitignore b/.gitignore index b163ca8c2f6e867fef2ed5e9c7038ac42673cbd7..5edc1f0182d024a9fb47e0b0a839a63ddf8363ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /unpackage +.DS_Store \ No newline at end of file diff --git a/uni_modules/uni-getbatteryinfo/utssdk/app-ios/config.json b/uni_modules/uni-getbatteryinfo/utssdk/app-ios/config.json index 721b81e0240705a87ec0761aa9eb6f4e188769cb..2281f666c94f6793f04f49f1d49f0c2061dbb186 100644 --- a/uni_modules/uni-getbatteryinfo/utssdk/app-ios/config.json +++ b/uni_modules/uni-getbatteryinfo/utssdk/app-ios/config.json @@ -1,3 +1,3 @@ { - "deploymentTarget": "9" + "deploymentTarget": "9.0" } \ No newline at end of file diff --git a/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts b/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts index 566f7ab93096abe49be7c65fb2fb79ad71b0139a..5d2d48f8c2e5f263324dd0df8d06f305cabb05e0 100644 --- a/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts +++ b/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts @@ -1,20 +1,30 @@ +// 引用 iOS 原生平台 api import { UIDevice } from "UIKit"; +import { Int } from 'Swift'; +/** + * 定义 接口参数 + */ type GetBatteryInfoOptions = { - success?: (res: UTSJSONObject) => void; - fail?: (res: UTSJSONObject) => void; - complete?: (res: UTSJSONObject) => void; + success?: (res: object) => void; + fail?: (res: object) => void; + complete?: (res: object) => void; }; +/** + * 导出 获取电量方法 + */ export default function getBatteryInfo(options: GetBatteryInfoOptions) { + // 开启电量检测 UIDevice.current.isBatteryMonitoringEnabled = true + // 返回数据 const res = { errMsg: "getBatteryInfo:ok", - level: Number(UIDevice.current.batteryLevel * 100), + level: new Int(UIDevice.current.batteryLevel * 100), isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging, }; options.success?.(res); options.complete?.(res); -} +} \ No newline at end of file diff --git a/uni_modules/uni-memorywarning/readme.md b/uni_modules/uni-memorywarning/readme.md index 32171100b8b377e866dbc4b5e04ce5b88b76e94e..56cf8f9b3f657dde750a29dbbadde61a47522843 100644 --- a/uni_modules/uni-memorywarning/readme.md +++ b/uni_modules/uni-memorywarning/readme.md @@ -2,14 +2,16 @@ ### uni.onMemoryWarning(function listener) -监听内存不足告警事件(目前仅Android) +监听内存不足告警事件 -当 Android 向小程序进程发出内存警告时,触发该事件。 +当系统应用进程发出内存警告时,触发该事件。 触发该事件不意味应用被杀,大部分情况下仅仅是告警,开发者可在收到通知后回收一些不必要资源。 -返回值说明: +返回值说明: + +**注意平台差异:仅Android平台有返回值,iOS平台无返回值** ```kotlin @@ -65,7 +67,7 @@ int TRIM_MEMORY_COMPLETE = 80; ### uni.offMemoryWarning(function listener) -移除内存不足告警事件的监听函数(目前仅Android) +移除内存不足告警事件的监听函数 onMemoryWarning 传入的监听函数。不传此参数则移除所有监听函数。 diff --git a/uni_modules/uni-memorywarning/utssdk/app-ios/index.uts b/uni_modules/uni-memorywarning/utssdk/app-ios/index.uts index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..329579533b81d0cbd09719b55bd88e6326eb3ffb 100644 --- a/uni_modules/uni-memorywarning/utssdk/app-ios/index.uts +++ b/uni_modules/uni-memorywarning/utssdk/app-ios/index.uts @@ -0,0 +1,40 @@ +import { NotificationCenter } from 'Foundation'; +import { UIApplication } from "UIKit" + +class MemoryWarningTool { + static listener: UTSCallback | null; + + // 监听截屏 + static listenMemoryWarning(callback: UTSCallback | null) { + this.listener = callback + + // 注册监听截屏事件及回调方法 + // target-action 回调方法需要通过 Selector("方法名") 构建 + const method = Selector("receiveMemoryWarning") + NotificationCenter.default.addObserver(this, selector = method, name = UIApplication.didReceiveMemoryWarningNotification, object = null) + } + + // 内存警告回调的方法 + // target-action 的方法前需要添加 @objc 前缀 + @objc static receiveMemoryWarning() { + // 回调 + this.listener?.({}) + } + + // 移除监听事件 + static removeListen(callback: UTSCallback | null) { + this.listener = null + NotificationCenter.default.removeObserver(this) + callback?.({}) + } +} + +// 开启监听内存警告 +export function onMemoryWarning(callback: UTSCallback | null) { + MemoryWarningTool.listenMemoryWarning(callback) +} + +// 关闭监听内存警告 +export function offMemoryWarning(callback: UTSCallback | null) { + MemoryWarningTool.removeListen(callback) +} \ No newline at end of file diff --git a/uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts b/uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts index 1151d9e520c6da0284812eac14f2147aa243919f..18395aa6b4937d9a8ffd6889b731e79bd5fb4f5d 100644 --- a/uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts +++ b/uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts @@ -1,14 +1,14 @@ -import { NotificationCenter} from 'Foundation'; +import { NotificationCenter } from 'Foundation'; import { UIApplication } from "UIKit" /** * 定义监听截屏事件工具类 */ class CaptureScreenTool { - static listener?: UTSCallback; + static listener: UTSCallback | null; // 监听截屏 - static listenCaptureScreen(callback?: UTSCallback) { + static listenCaptureScreen(callback: UTSCallback | null) { this.listener = callback // 注册监听截屏事件及回调方法 @@ -20,30 +20,28 @@ class CaptureScreenTool { // 捕获截屏回调的方法 // target-action 的方法前需要添加 @objc 前缀 @objc static userDidTakeScreenshot() { - const obj = new UTSJSONObject() // 回调 - this.listener?.(obj) + this.listener?.({}) } // 移除监听事件 - static removeListen(callback?: UTSCallback) { + static removeListen(callback: UTSCallback | null) { this.listener = null NotificationCenter.default.removeObserver(this) - const obj = new UTSJSONObject() - callback?.(obj) + callback?.({}) } } /** * 开启截图监听 */ -export function onUserCaptureScreen(callback?: UTSCallback) { +export function onUserCaptureScreen(callback: UTSCallback | null) { CaptureScreenTool.listenCaptureScreen(callback) } /** * 关闭截屏监听 */ -export function offUserCaptureScreen(callback?: UTSCallback) { +export function offUserCaptureScreen(callback: UTSCallback | null) { CaptureScreenTool.removeListen(callback) -} +} \ No newline at end of file