Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
b23322d4
U
uni-api
项目概览
DCloud
/
uni-api
通知
677
Star
23
Fork
12
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
b23322d4
编写于
5月 29, 2023
作者:
lizhongyi_
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
uni-getbatteryinfo新增同步获取电量api
上级
aa42bb75
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
58 addition
and
5 deletion
+58
-5
uni_modules/uni-getbatteryinfo/package.json
uni_modules/uni-getbatteryinfo/package.json
+1
-1
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
+14
-1
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
+43
-3
未找到文件。
uni_modules/uni-getbatteryinfo/package.json
浏览文件 @
b23322d4
...
@@ -32,7 +32,7 @@
...
@@ -32,7 +32,7 @@
},
},
"uni_modules"
:
{
"uni_modules"
:
{
"uni-ext-api"
:
{
"uni-ext-api"
:
{
"uni"
:
[
"getBatteryInfo"
]
"uni"
:
[
"getBatteryInfo"
,
"getBatteryInfoSync"
]
},
},
"dependencies"
:
[],
"dependencies"
:
[],
"encrypt"
:
[],
"encrypt"
:
[],
...
...
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
浏览文件 @
b23322d4
...
@@ -20,4 +20,17 @@ export const getBatteryInfo : GetBatteryInfo = function (options) {
...
@@ -20,4 +20,17 @@ export const getBatteryInfo : GetBatteryInfo = function (options) {
};
};
options.success?.(res);
options.success?.(res);
options.complete?.(res);
options.complete?.(res);
}
}
\ No newline at end of file
export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryInfoResult {
// 开启电量检测
UIDevice.current.isBatteryMonitoringEnabled = true
// 返回数据
const res : GetBatteryInfoResult = {
level: Number(UIDevice.current.batteryLevel * 100),
isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,
};
return res;
}
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
浏览文件 @
b23322d4
...
@@ -44,6 +44,17 @@ export type GetBatteryInfoOptions = {
...
@@ -44,6 +44,17 @@ export type GetBatteryInfoOptions = {
* 接口调用成功的回调
* 接口调用成功的回调
*/
*/
complete ?: (res : any) => void
complete ?: (res : any) => void
}
export type GetBatteryInfoResult = {
/**
* 设备电量,范围1 - 100
*/
level : number,
/**
* 是否正在充电中
*/
isCharging : boolean
}
}
/**
/**
...
@@ -58,8 +69,10 @@ export type GetBatteryInfoOptions = {
...
@@ -58,8 +69,10 @@ export type GetBatteryInfoOptions = {
* @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false })
* @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false })
* @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" })
* @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" })
*/
*/
export type GetBatteryInfo = (options : GetBatteryInfoOptions) => void
export type GetBatteryInfo = (options : GetBatteryInfoOptions) => void
export type GetBatteryInfoSync = () => GetBatteryInfoResult
interface Uni {
interface Uni {
...
@@ -85,7 +98,7 @@ interface Uni {
...
@@ -85,7 +98,7 @@ interface Uni {
* "unixVer": "3.9.0"
* "unixVer": "3.9.0"
* },
* },
* "ios": {
* "ios": {
* "osVer": "
8
.0",
* "osVer": "
9
.0",
* "uniVer": "3.6.11",
* "uniVer": "3.6.11",
* "unixVer": "3.9.0"
* "unixVer": "3.9.0"
* }
* }
...
@@ -94,6 +107,33 @@ interface Uni {
...
@@ -94,6 +107,33 @@ interface Uni {
* @uniVueVersion 2,3 //支持的vue版本
* @uniVueVersion 2,3 //支持的vue版本
*
*
*/
*/
getBatteryInfo : GetBatteryInfo
getBatteryInfo : GetBatteryInfo,
/**
* 同步获取电池电量信息
* @description 获取电池电量信息
* @example
* ```typescript
* uni.getBatteryInfo()
* ```
* @remark
* - 该接口需要同步调用
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.6.11",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.6.11",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*
*/
getBatteryInfoSync: GetBatteryInfoSync
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录