提交 1256a2b8 编写于 作者: DCloud_iOS_XHY's avatar DCloud_iOS_XHY

内存警告插件 方法参数改回 UTSCallback 类型

上级 e77623e7
...@@ -2,13 +2,11 @@ import { NotificationCenter } from 'Foundation'; ...@@ -2,13 +2,11 @@ import { NotificationCenter } from 'Foundation';
import { UIApplication } from "UIKit" import { UIApplication } from "UIKit"
import { Selector } from "ObjectiveC" import { Selector } from "ObjectiveC"
import { OffMemoryWarning, OnMemoryWarning, OnMemoryWarningCallback, OnMemoryWarningCallbackResult } from "../interface.uts"
class MemoryWarningTool { class MemoryWarningTool {
static listeners: OnMemoryWarningCallback[] = [] static listeners: UTSCallback[] = []
// 监听内存警告 // 监听内存警告
static listenMemoryWarning(callback: OnMemoryWarningCallback) { static listenMemoryWarning(callback: UTSCallback) {
// 只有首次才需要注册监听事件 // 只有首次才需要注册监听事件
if (this.listeners.length == 0) { if (this.listeners.length == 0) {
...@@ -25,13 +23,12 @@ class MemoryWarningTool { ...@@ -25,13 +23,12 @@ class MemoryWarningTool {
@objc static receiveMemoryWarning() { @objc static receiveMemoryWarning() {
// 触发回调 // 触发回调
this.listeners.forEach(listener => { this.listeners.forEach(listener => {
const ret: OnMemoryWarningCallbackResult = {} listener({})
listener(ret)
}) })
} }
// 移除监听事件 // 移除监听事件
static removeListen(callback: OnMemoryWarningCallback | null) { static removeListen(callback: UTSCallback | null) {
// 移除所有监听 // 移除所有监听
if (callback == null) { if (callback == null) {
this.listeners = [] this.listeners = []
...@@ -49,11 +46,11 @@ class MemoryWarningTool { ...@@ -49,11 +46,11 @@ class MemoryWarningTool {
} }
// 开启监听内存警告 // 开启监听内存警告
export const onMemoryWarning : OnMemoryWarning = function (callback: OnMemoryWarningCallback) { export function onMemoryWarning(callback: UTSCallback) {
MemoryWarningTool.listenMemoryWarning(callback) MemoryWarningTool.listenMemoryWarning(callback)
} }
// 关闭监听内存警告 // 关闭监听内存警告
export const offMemoryWarning : OffMemoryWarning = function (callback: OnMemoryWarningCallback | null) { export function offMemoryWarning(callback: UTSCallback | null) {
MemoryWarningTool.removeListen(callback) MemoryWarningTool.removeListen(callback)
} }
\ No newline at end of file
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册