提交 c4d182b7 编写于 作者: 杜庆泉's avatar 杜庆泉

手动合并dev 到 alpha

...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
/.hbuilderx /.hbuilderx
/.vite /.vite
.DS_Store .DS_Store
<<<<<<< HEAD
=======
>>>>>>> dev
env.js env.js
jest.config.js jest.config.js
autotest.reporter.js autotest.reporter.js
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<button @tap="testGetBatteryInfoSync">同步获取电池电量</button> <button @tap="testGetBatteryInfoSync">同步获取电池电量</button>
<button @tap="testonMemoryWarning">开启内存不足告警监听</button> <button @tap="testonMemoryWarning">开启内存不足告警监听</button>
<button @tap="testoffMemoryWarning">关闭内存不足告警监听</button> <button @tap="testoffMemoryWarning">关闭内存不足告警监听</button>
<button @tap="getLocationTest" style="width: 100%;">获取定位</button>
</view> </view>
</template> </template>
...@@ -32,7 +32,8 @@ ...@@ -32,7 +32,8 @@
memListener:null, memListener:null,
setUserCaptureScreenFlag: false, setUserCaptureScreenFlag: false,
setUserCaptureScreenText: '禁止截屏', setUserCaptureScreenText: '禁止截屏',
permissionGranted: false permissionGranted: false,
id:0
} }
}, },
onLoad() { onLoad() {
...@@ -45,7 +46,19 @@ ...@@ -45,7 +46,19 @@
fn:function(res){ fn:function(res){
console.log(res) console.log(res)
}, },
getLocationTest() {
console.log(" ------- getLocationTest: ");
uni.getLocation({
type: 'gcj02 ',
success (res) {
console.log(" success ",res);
},fail (res) {
console.log(" fail ",res);
}
})
},
onGetWifiList2_assert0() { onGetWifiList2_assert0() {
console.log(" ------- onGetWifiList2_assert0: ",this.id);
const fn = res => console.log('onGetWifiList res', res) const fn = res => console.log('onGetWifiList res', res)
uni.startWifi({success(){ uni.startWifi({success(){
uni.onGetWifiList(fn) uni.onGetWifiList(fn)
...@@ -62,6 +75,7 @@ ...@@ -62,6 +75,7 @@
} }
}) })
}}) }})
this.id++
}, },
testConnnectWifi(){ testConnnectWifi(){
......
...@@ -4,7 +4,7 @@ export interface Uni { ...@@ -4,7 +4,7 @@ export interface Uni {
* *
* @tutorial http://uniapp.dcloud.io/api/location/location?id=getlocation * @tutorial http://uniapp.dcloud.io/api/location/location?id=getlocation
*/ */
getLocation: GetLocation; getLocation(options: GetLocationOptions) : void;
} }
export type GetLocation = (options: GetLocationOptions) => void; export type GetLocation = (options: GetLocationOptions) => void;
......
## 1.3.1(2023-09-15)
app端适配使用UniError
## 1.3.0(2023-05-30)
新增 同步获取电量api
## 1.2.0(2022-10-17) ## 1.2.0(2022-10-17)
实现百度小程序/支付宝小程序/QQ小程序获取电量 实现百度小程序/支付宝小程序/QQ小程序获取电量
## 1.1.0(2022-10-17) ## 1.1.0(2022-10-17)
实现ios平台获取电量 实现ios平台获取电量
......
{ {
"id": "uni-getbatteryinfo", "id": "uni-getbatteryinfo",
"displayName": "uni-getbatteryinfo", "displayName": "uni-getbatteryinfo",
"version": "1.2.0", "version": "1.3.1",
"description": "使用uts开发,实现在多个平台获取电池电量功能", "description": "使用uts开发,实现在多个平台获取电池电量功能",
"keywords": [ "keywords": [
"battery" "battery"
], ],
"repository": "", "repository": "",
"engines": { "engines": {
"HBuilderX": "^3.6.0" "HBuilderX": "^3.9.0"
}, },
"dcloudext": { "dcloudext": {
"type": "uts", "type": "uts",
...@@ -32,7 +32,12 @@ ...@@ -32,7 +32,12 @@
}, },
"uni_modules": { "uni_modules": {
"uni-ext-api": { "uni-ext-api": {
"uni": ["getBatteryInfo", "getBatteryInfoSync"] "uni": {
"getBatteryInfo": "getBatteryInfo",
"getBatteryInfoSync": {
"web": false
}
}
}, },
"dependencies": [], "dependencies": [],
"encrypt": [], "encrypt": [],
......
import Context from "android.content.Context"; import Context from "android.content.Context";
import BatteryManager from "android.os.BatteryManager"; import BatteryManager from "android.os.BatteryManager";
import { UTSAndroid } from "io.dcloud.uts";
import { GetBatteryInfo, GetBatteryInfoSuccess, GetBatteryInfoFail, GetBatteryInfoResult,GetBatteryInfoSync } from '../interface.uts' import { GetBatteryInfo, GetBatteryInfoOptions, GetBatteryInfoSuccess, GetBatteryInfoResult,GetBatteryInfoSync } from '../interface.uts'
import IntentFilter from 'android.content.IntentFilter';
import Intent from 'android.content.Intent';
/** /**
* 异步获取电量 * 异步获取电量
* @param {Object} options
*/ */
export const getBatteryInfo : GetBatteryInfo = function (options) { export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInfoOptions) {
const context = UTSAndroid.getAppContext(); const context = UTSAndroid.getAppContext();
if (context != null) { if (context != null) {
const manager = context.getSystemService( const manager = context.getSystemService(
...@@ -16,20 +20,21 @@ export const getBatteryInfo : GetBatteryInfo = function (options) { ...@@ -16,20 +20,21 @@ export const getBatteryInfo : GetBatteryInfo = function (options) {
const level = manager.getIntProperty( const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY BatteryManager.BATTERY_PROPERTY_CAPACITY
); );
let ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
let batteryStatus = context.registerReceiver(null, ifilter);
let status = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
let isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
const res : GetBatteryInfoSuccess = { const res : GetBatteryInfoSuccess = {
errMsg: 'getBatteryInfo:ok', errMsg: 'getBatteryInfo:ok',
level, level,
isCharging: manager.isCharging() isCharging: isCharging
} }
options.success?.(res) options.success?.(res)
options.complete?.(res) options.complete?.(res)
} else { } else {
const res : GetBatteryInfoFail = { const res = new UniError("uni-getBatteryInfo", 1001, "getBatteryInfo:fail getAppContext is null")
errSubject: "uni-getBatteryInfo",
errCode: 1001,
errMsg: 'getBatteryInfo:fail getAppContext is null',
cause: null
}
options.fail?.(res) options.fail?.(res)
options.complete?.(res) options.complete?.(res)
} }
...@@ -42,6 +47,8 @@ export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryIn ...@@ -42,6 +47,8 @@ export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryIn
const context = UTSAndroid.getAppContext(); const context = UTSAndroid.getAppContext();
if (context != null) { if (context != null) {
const manager = context.getSystemService( const manager = context.getSystemService(
Context.BATTERY_SERVICE Context.BATTERY_SERVICE
) as BatteryManager; ) as BatteryManager;
...@@ -49,12 +56,19 @@ export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryIn ...@@ -49,12 +56,19 @@ export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryIn
BatteryManager.BATTERY_PROPERTY_CAPACITY BatteryManager.BATTERY_PROPERTY_CAPACITY
); );
let ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
let batteryStatus = context.registerReceiver(null, ifilter);
let status = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
let isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
const res : GetBatteryInfoResult = { const res : GetBatteryInfoResult = {
level: level, level: level,
isCharging: manager.isCharging() isCharging: isCharging
}; };
return res; return res;
} else { }
else {
/** /**
* 无有效上下文 * 无有效上下文
*/ */
......
{
"deploymentTarget": "9"
}
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { UIDevice } from "UIKit"; import { UIDevice } from "UIKit";
import { Int } from 'Swift'; import { Int } from 'Swift';
import { GetBatteryInfo, GetBatteryInfoSuccess } from '../interface.uts'; import { GetBatteryInfo, GetBatteryInfoSuccess, GetBatteryInfoResult, GetBatteryInfoSync } from '../interface.uts';
/** /**
* 导出 获取电量方法 * 导出 获取电量方法
......
...@@ -34,4 +34,9 @@ declare interface Uni { ...@@ -34,4 +34,9 @@ declare interface Uni {
* 文档: [https://uniapp.dcloud.net.cn/api/system/batteryInfo.html](https://uniapp.dcloud.net.cn/api/system/batteryInfo.html) * 文档: [https://uniapp.dcloud.net.cn/api/system/batteryInfo.html](https://uniapp.dcloud.net.cn/api/system/batteryInfo.html)
*/ */
getBatteryInfo(option?: UniNamespace.GetBatteryInfoOption): void; getBatteryInfo(option?: UniNamespace.GetBatteryInfoOption): void;
/**
* 同步获取电池电量信息
*/
getBatteryInfoSync(): UniNamespace.GetBatteryInfoSuccessCallbackResult;
} }
...@@ -10,24 +10,24 @@ export type GetBatteryInfoSuccess = { ...@@ -10,24 +10,24 @@ export type GetBatteryInfoSuccess = {
isCharging : boolean isCharging : boolean
} }
export type GetBatteryInfoFail = { // export type GetBatteryInfoFail = {
/** // /**
* 错误码 // * 错误码
*/ // */
errCode : number, // errCode : number,
/** // /**
* 调用API的名称 // * 调用API的名称
*/ // */
errSubject : string, // errSubject : string,
/** // /**
* 错误的详细信息 // * 错误的详细信息
*/ // */
errMsg : string, // errMsg : string,
/** // /**
* 错误来源 // * 错误来源
*/ // */
cause : any | null // cause : any | null
} // }
...@@ -39,7 +39,7 @@ export type GetBatteryInfoOptions = { ...@@ -39,7 +39,7 @@ export type GetBatteryInfoOptions = {
/** /**
* 接口调用失败的回调函数 * 接口调用失败的回调函数
*/ */
fail ?: (res : GetBatteryInfoFail) => void fail ?: (res : UniError) => void
/** /**
* 接口调用成功的回调 * 接口调用成功的回调
*/ */
...@@ -107,7 +107,7 @@ interface Uni { ...@@ -107,7 +107,7 @@ interface Uni {
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* *
*/ */
getBatteryInfo : GetBatteryInfo, getBatteryInfo (options : GetBatteryInfoOptions) : void,
/** /**
* 同步获取电池电量信息 * 同步获取电池电量信息
* @description 获取电池电量信息 * @description 获取电池电量信息
...@@ -134,6 +134,6 @@ interface Uni { ...@@ -134,6 +134,6 @@ interface Uni {
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* *
*/ */
getBatteryInfoSync: GetBatteryInfoSync getBatteryInfoSync():GetBatteryInfoResult
} }
export function getBatteryInfo(options) { export function getBatteryInfo(options) {
return my.getBatteryInfo(options) return my.getBatteryInfo(options)
} }
export function getBatteryInfoSync(options) {
return my.getBatteryInfoSync(options)
}
export function getBatteryInfo(options) { export function getBatteryInfo(options) {
return swan.getBatteryInfo(options) return swan.getBatteryInfo(options)
} }
export function getBatteryInfoSync(options) {
return swan.getBatteryInfoSync(options)
}
export function getBatteryInfo(options) { export function getBatteryInfo(options) {
return qq.getBatteryInfo(options) return qq.getBatteryInfo(options)
} }
export function getBatteryInfoSync(options) {
return qq.getBatteryInfoSync(options)
}
export function getBatteryInfo(options) { export function getBatteryInfo(options) {
return wx.getBatteryInfo(options) return wx.getBatteryInfo(options)
} }
export function getBatteryInfoSync(options) {
return wx.getBatteryInfoSync(options)
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"description": "UTS 实现内存警告监听", "description": "UTS 实现内存警告监听",
"keywords": [ "keywords": [
"onMemoryWarning" "onMemoryWarning"
], ],
"repository": "", "repository": "",
"engines": { "engines": {
"HBuilderX": "^3.6.11" "HBuilderX": "^3.6.11"
...@@ -31,17 +31,15 @@ ...@@ -31,17 +31,15 @@
"npmurl": "" "npmurl": ""
}, },
"uni_modules": { "uni_modules": {
"uni-ext-api":{ "uni-ext-api": {
"uni": { "uni": {
"onMemoryWarning": "onMemoryWarning", "onMemoryWarning": {
"offMemoryWarning":"offMemoryWarning" "web": false
}, },
"mp-weixin":false, "offMemoryWarning": {
"mp-alipay":false, "web": false
"mp-baidu":false, }
"mp-qq":false, }
"mp-kuaishou":false,
"mp-jd":false
}, },
"dependencies": [], "dependencies": [],
"encrypt": [], "encrypt": [],
......
...@@ -46,6 +46,7 @@ class MemoryWarningTool { ...@@ -46,6 +46,7 @@ class MemoryWarningTool {
} }
} }
// 开启监听内存警告 // 开启监听内存警告
export const onMemoryWarning : OnMemoryWarning = function (callback: UTSCallback) { export const onMemoryWarning : OnMemoryWarning = function (callback: UTSCallback) {
MemoryWarningTool.listenMemoryWarning(callback) MemoryWarningTool.listenMemoryWarning(callback)
......
...@@ -25,8 +25,9 @@ export interface Uni { ...@@ -25,8 +25,9 @@ export interface Uni {
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/ */
onMemoryWarning : OnMemoryWarning, onMemoryWarning(callback: UTSCallback) : void,
/** /**
* 取消监听内存不足告警事件 * 取消监听内存不足告警事件
* *
...@@ -48,6 +49,7 @@ export interface Uni { ...@@ -48,6 +49,7 @@ export interface Uni {
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/ */
offMemoryWarning : OffMemoryWarning offMemoryWarning(callback : UTSCallback | null) : void
} }
\ No newline at end of file
...@@ -33,9 +33,16 @@ ...@@ -33,9 +33,16 @@
"uni_modules": { "uni_modules": {
"uni-ext-api":{ "uni-ext-api":{
"uni": { "uni": {
"onUserCaptureScreen": "onUserCaptureScreen", "onUserCaptureScreen": {
"offUserCaptureScreen": "offUserCaptureScreen", "web": false
"setUserCaptureScreen": "setUserCaptureScreen" },
"offUserCaptureScreen": {
"web": false
},
"setUserCaptureScreen": {
"web": false,
"mp-weixin": false
}
} }
}, },
"dependencies": [], "dependencies": [],
......
...@@ -9,6 +9,7 @@ import Environment from "android.os.Environment"; ...@@ -9,6 +9,7 @@ import Environment from "android.os.Environment";
import System from 'java.lang.System'; import System from 'java.lang.System';
import WindowManager from 'android.view.WindowManager'; import WindowManager from 'android.view.WindowManager';
import { OnUserCaptureScreenCallbackResult, UserCaptureScreenCallback, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreenSuccess, SetUserCaptureScreenOptions, SetUserCaptureScreen } from "../interface.uts"; import { OnUserCaptureScreenCallbackResult, UserCaptureScreenCallback, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreenSuccess, SetUserCaptureScreenOptions, SetUserCaptureScreen } from "../interface.uts";
import string from 'android.R.string';
/** /**
...@@ -34,9 +35,9 @@ class ScreenFileObserver extends FileObserver { ...@@ -34,9 +35,9 @@ class ScreenFileObserver extends FileObserver {
*/ */
private screenFile : File; private screenFile : File;
constructor(screenFile : File) { constructor(screenFileStr : string) {
super(screenFile); super(screenFileStr);
this.screenFile = screenFile; this.screenFile = new File(screenFileStr);
} }
override onEvent(event : Int, path : string | null) : void { override onEvent(event : Int, path : string | null) : void {
...@@ -83,7 +84,7 @@ export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : Us ...@@ -83,7 +84,7 @@ export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : Us
} }
// 先结束监听 再开启监听 // 先结束监听 再开启监听
observer?.stopWatching(); observer?.stopWatching();
observer = new ScreenFileObserver(directory_screenshot); observer = new ScreenFileObserver(directory_screenshot.getPath());
observer?.startWatching(); observer?.startWatching();
...@@ -92,7 +93,6 @@ export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : Us ...@@ -92,7 +93,6 @@ export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : Us
observer = null observer = null
}) })
} }
/** /**
......
...@@ -3,7 +3,7 @@ import { CGRect } from "CoreFoundation"; ...@@ -3,7 +3,7 @@ import { CGRect } from "CoreFoundation";
import { UIApplication, UIView, UITextField, UIScreen, UIDevice } from "UIKit" import { UIApplication, UIView, UITextField, UIScreen, UIDevice } from "UIKit"
import { UTSiOS } from "DCloudUTSFoundation" import { UTSiOS } from "DCloudUTSFoundation"
import { DispatchQueue } from 'Dispatch'; import { DispatchQueue } from 'Dispatch';
import { SetUserCaptureScreenOptions, OnUserCaptureScreenCallbackResult, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreen, UserCaptureScreenCallback, SetUserCaptureScreenSuccess, SetUserCaptureScreenFail } from "../interface.uts" import { SetUserCaptureScreenOptions, OnUserCaptureScreenCallbackResult, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreen, UserCaptureScreenCallback, SetUserCaptureScreenSuccess } from "../interface.uts"
/** /**
* 定义监听截屏事件工具类 * 定义监听截屏事件工具类
...@@ -119,20 +119,12 @@ export const offUserCaptureScreen : OffUserCaptureScreen = function (callback : ...@@ -119,20 +119,12 @@ export const offUserCaptureScreen : OffUserCaptureScreen = function (callback :
*/ */
export const setUserCaptureScreen : SetUserCaptureScreen = function (options : SetUserCaptureScreenOptions) { export const setUserCaptureScreen : SetUserCaptureScreen = function (options : SetUserCaptureScreenOptions) {
if (UIDevice.current.systemVersion < "13.0") { if (UIDevice.current.systemVersion < "13.0") {
let res: SetUserCaptureScreenFail = { let res = new UniError("uni-usercapturescreen", 12001, "setUserCaptureScreen:system not support")
errCode: 12001,
errSubject: "uni-usercapturescreen",
errMsg: "setUserCaptureScreen:system not support"
}
options.fail?.(res); options.fail?.(res);
options.complete?.(res); options.complete?.(res);
} else if (UIDevice.current.systemVersion == "15.1") { } else if (UIDevice.current.systemVersion == "15.1") {
let res: SetUserCaptureScreenFail = { let res = new UniError("uni-usercapturescreen", 12010, "setUserCaptureScreen:system internal error")
errCode: 12010,
errSubject: "uni-usercapturescreen",
errMsg: "setUserCaptureScreen:system internal error"
}
options.fail?.(res); options.fail?.(res);
options.complete?.(res); options.complete?.(res);
} else { } else {
......
...@@ -23,25 +23,6 @@ export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) ...@@ -23,25 +23,6 @@ export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null)
export type SetUserCaptureScreenSuccess = { export type SetUserCaptureScreenSuccess = {
} }
/**
* uni.setUserCaptureScreen失败回调参数
*/
export type SetUserCaptureScreenFail = {
/**
* 错误码
* 12001:system not support
* 12010:system internal error
*/
errCode : number,
/**
* 调用API的名称
*/
errSubject : string,
/**
* 错误的详细信息
*/
errMsg : string,
}
/** /**
* uni.setUserCaptureScreen成功回调函数定义 * uni.setUserCaptureScreen成功回调函数定义
...@@ -51,7 +32,7 @@ export type SetUserCaptureScreenSuccessCallback = (res : SetUserCaptureScreenSuc ...@@ -51,7 +32,7 @@ export type SetUserCaptureScreenSuccessCallback = (res : SetUserCaptureScreenSuc
/** /**
* uni.setUserCaptureScreen失败回调函数定义 * uni.setUserCaptureScreen失败回调函数定义
*/ */
export type SetUserCaptureScreenFailCallback = (res : SetUserCaptureScreenFail) => void export type SetUserCaptureScreenFailCallback = (res : UniError) => void
/** /**
* uni.setUserCaptureScreen完成回调函数定义 * uni.setUserCaptureScreen完成回调函数定义
...@@ -108,8 +89,9 @@ export interface Uni { ...@@ -108,8 +89,9 @@ export interface Uni {
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/ */
onUserCaptureScreen : OnUserCaptureScreen, onUserCaptureScreen(callback : UserCaptureScreenCallback | null) : void,
/** /**
* 关闭截屏监听 * 关闭截屏监听
* *
...@@ -131,8 +113,9 @@ export interface Uni { ...@@ -131,8 +113,9 @@ export interface Uni {
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/ */
offUserCaptureScreen : OffUserCaptureScreen, offUserCaptureScreen(callback : UserCaptureScreenCallback | null) : void,
/** /**
* 设置防截屏 * 设置防截屏
* *
...@@ -155,5 +138,5 @@ export interface Uni { ...@@ -155,5 +138,5 @@ export interface Uni {
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
*/ */
setUserCaptureScreen : SetUserCaptureScreen setUserCaptureScreen(options : SetUserCaptureScreenOptions) : void
} }
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"description": "wifi管理", "description": "wifi管理",
"keywords": [ "keywords": [
"wifi" "wifi"
], ],
"repository": "", "repository": "",
"engines": { "engines": {
"HBuilderX": "^3.6.11" "HBuilderX": "^3.6.11"
...@@ -31,19 +31,41 @@ ...@@ -31,19 +31,41 @@
"npmurl": "" "npmurl": ""
}, },
"uni_modules": { "uni_modules": {
"uni-ext-api":{ "uni-ext-api": {
"uni": { "uni": {
"startWifi": "startWifi", "startWifi": {
"stopWifi": "stopWifi", "web": false
"connectWifi":"connectWifi", },
"getConnectedWifi": "getConnectedWifi", "stopWifi": {
"getWifiList":"getWifiList", "web": false
"onGetWifiList":"onGetWifiList", },
"offGetWifiList":"offGetWifiList", "connectWifi": {
"onWifiConnected":"onWifiConnected", "web": false
"offWifiConnected":"offWifiConnected", },
"onWifiConnectedWithPartialInfo":"onWifiConnectedWithPartialInfo", "getConnectedWifi": {
"offWifiConnectedWithPartialInfo":"offWifiConnectedWithPartialInfo" "web": false
},
"getWifiList": {
"web": false
},
"onGetWifiList": {
"web": false
},
"offGetWifiList": {
"web": false
},
"onWifiConnected": {
"web": false
},
"offWifiConnected": {
"web": false
},
"onWifiConnectedWithPartialInfo": {
"web": false
},
"offWifiConnectedWithPartialInfo": {
"web": false
}
} }
}, },
"dependencies": [], "dependencies": [],
......
{
"minSdkVersion": "19"
}
\ No newline at end of file
...@@ -306,17 +306,8 @@ class CustomBroadcastReceiver extends BroadcastReceiver { ...@@ -306,17 +306,8 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
if (intent.action == WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) { if (intent.action == WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) {
startWifiScaning = false; startWifiScaning = false;
let ret : UniWifiResult = {
errCode: 0,
errSubject: "uni-getWifiList",
errMsg: "getWifiList:ok"
}
if(Global.supendGetWifiSuccess != null){
Global.supendGetWifiSuccess?.(ret)
}
if(Global.supendGetWifiComplete != null){
Global.supendGetWifiComplete?.(ret)
}
// wifi 扫描结果回调 // wifi 扫描结果回调
let results = this.mWifiManager!.scanResults; let results = this.mWifiManager!.scanResults;
...@@ -336,15 +327,27 @@ class CustomBroadcastReceiver extends BroadcastReceiver { ...@@ -336,15 +327,27 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
const data = new JSONObject(); const data = new JSONObject();
data["wifiList"] = Global.scanList data["wifiList"] = Global.scanList
Global.onGetWifiListCallback?.(data); Global.onGetWifiListCallback?.(data);
/**
* 确保onGetWifiList 只会被执行一次
*/
Global.onGetWifiListCallback = null
} }
// for (let perCallback in Global.onGetWifiListCallback) {
// const data = new JSONObject();
// data["wifiList"] = Global.scanList
// perCallback(data);
// }
} }
let ret : UniWifiResult = {
errCode: 0,
errSubject: "uni-getWifiList",
errMsg: "getWifiList:ok"
}
if(Global.supendGetWifiSuccess != null){
Global.supendGetWifiSuccess?.(ret)
Global.supendGetWifiSuccess = null
}
if(Global.supendGetWifiComplete != null){
Global.supendGetWifiComplete?.(ret)
Global.supendGetWifiComplete = null
}
} }
} }
...@@ -367,18 +370,21 @@ export function startWifi(option : WifiOption) { ...@@ -367,18 +370,21 @@ export function startWifi(option : WifiOption) {
// 需要先开启wifi,才能使用后续的功能 // 需要先开启wifi,才能使用后续的功能
let requestCode = 1001; let requestCode = 1001;
let permissionWifi = arrayOf("android.permission.ACCESS_FINE_LOCATION"); let permissionWifi = arrayOf("android.permission.ACCESS_FINE_LOCATION");
var result : UniWifiResult = {
let result : UniWifiResult = {
errCode: 12001, errCode: 12001,
errMsg: "startWifi:premission loss", errMsg: "startWifi:premission loss",
errSubject: "uni-startWifi" errSubject: "uni-startWifi"
} }
// 检查权限 // 检查权限
if (ActivityCompat.checkSelfPermission(UTSAndroid.getUniActivity()!, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.checkSelfPermission(UTSAndroid.getUniActivity()!, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(UTSAndroid.getUniActivity()!, permissionWifi, requestCode.toInt()) ActivityCompat.requestPermissions(UTSAndroid.getUniActivity()!, permissionWifi, requestCode.toInt())
// 尚不具备权限,返回错误 // 尚不具备权限,返回错误
option.fail?.(result) let err = new UniError("uni-startWifi",12001,"startWifi:premission loss");
option.complete?.(result) option.fail?.(err)
option.complete?.(err)
return; return;
} }
...@@ -389,11 +395,9 @@ export function startWifi(option : WifiOption) { ...@@ -389,11 +395,9 @@ export function startWifi(option : WifiOption) {
// 用户没有开启wifi 总开关 // 用户没有开启wifi 总开关
if (!wifiManager.isWifiEnabled()) { if (!wifiManager.isWifiEnabled()) {
// wifi 没开启 // wifi 没开启
result.errCode = 12005; let err = new UniError("uni-startWifi",12005,"wifi not turned on");
result.errMsg = "wifi not turned on"; option.fail?.(err);
option.complete?.(err);
option.fail?.(result);
option.complete?.(result);
return; return;
} }
// 初始化wifi 状态广播监听,后续所有的api,均基于此 // 初始化wifi 状态广播监听,后续所有的api,均基于此
...@@ -453,16 +457,13 @@ export function startWifi(option : WifiOption) { ...@@ -453,16 +457,13 @@ export function startWifi(option : WifiOption) {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
export function getWifiList(option : WifiOption) { export function getWifiList(option : WifiOption) {
var result : UniWifiResult = {
errCode: 12000,
errMsg: "getWifiList:fail:not invoke startWifi",
errSubject: "uni-getWifiList"
}
if (Global.mReceiver == null) { if (Global.mReceiver == null) {
// 还没调用startWifi 提示报错 // 还没调用startWifi 提示报错
option.fail?.(result) let err = new UniError("uni-getWifiList",12000,"getWifiList:fail:not invoke startWifi");
option.complete?.(result)
option.fail?.(err)
option.complete?.(err)
return return
} }
...@@ -547,11 +548,13 @@ export function offGetWifiList(callback? : UTSCallback) { ...@@ -547,11 +548,13 @@ export function offGetWifiList(callback? : UTSCallback) {
/** /**
* 真正执行wifi链接逻辑 * 真正执行wifi链接逻辑
*/ */
function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){ function realWifiConnect(option : WifiConnectOption){
if (Global.mReceiver == null || Global.scanList.length < 1) { if (Global.mReceiver == null || Global.scanList.length < 1) {
option.fail?.(result)
option.complete?.(result) let err = new UniError("uni-connectWifi",12000,"connectWifi:fail:not invoke startWifi");
option.fail?.(err)
option.complete?.(err)
return return
} }
...@@ -566,8 +569,9 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){ ...@@ -566,8 +569,9 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){
if (scanWifiInfo == null) { if (scanWifiInfo == null) {
// 不在扫描列表中返回错误 // 不在扫描列表中返回错误
option.fail?.(result) let err = new UniError("uni-connectWifi",12000,"connectWifi:fail:not invoke startWifi");
option.complete?.(result) option.fail?.(err)
option.complete?.(err)
return return
} }
...@@ -593,16 +597,16 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){ ...@@ -593,16 +597,16 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){
// add since 2023-03-28,如果当前系统大于等于android10, 则明确当前系统不支持 // add since 2023-03-28,如果当前系统大于等于android10, 则明确当前系统不支持
if(Build.VERSION.SDK_INT > 28){ if(Build.VERSION.SDK_INT > 28){
// 系统大于android 9 // 系统大于android 9
result.errCode = 12001 let err = new UniError("uni-connectWifi",12001,"connectWifi:system not support");
result.errMsg = "connectWifi:system not support" option.fail?.(err)
option.complete?.(err)
}else{ }else{
// 移除之前的配置失败了,返回错误,需要用户手动取消保存一下 // 移除之前的配置失败了,返回错误,需要用户手动取消保存一下
result.errCode = 12013 let err = new UniError("uni-connectWifi",12013,"connectWifi:wifi config may be expired");
result.errMsg = "connectWifi:wifi config may be expired" option.fail?.(err)
option.complete?.(err)
} }
option.fail?.(result)
option.complete?.(result)
return return
} }
...@@ -623,11 +627,11 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){ ...@@ -623,11 +627,11 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){
let netID = wifiManager.addNetwork(wifiConfigration); let netID = wifiManager.addNetwork(wifiConfigration);
// 如果-1 说明没添加上,报错即可 // 如果-1 说明没添加上,报错即可
if (netID < 0) { if (netID < 0) {
result.errCode = 12002
result.errMsg = "connectWifi:password error Wi-Fi"
option.fail?.(result) let err = new UniError("uni-connectWifi",12002,"connectWifi:password error Wi-Fi");
option.complete?.(result)
option.fail?.(err)
option.complete?.(err)
return return
} }
...@@ -636,11 +640,10 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){ ...@@ -636,11 +640,10 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){
let enabled = wifiManager.enableNetwork(netID, true); let enabled = wifiManager.enableNetwork(netID, true);
if (!enabled) { if (!enabled) {
result.errCode = 12007 let err = new UniError("uni-connectWifi",12007,"connectWifi:user denied");
result.errMsg = "connectWifi:user denied"
option.fail?.(result) option.fail?.(err)
option.complete?.(result) option.complete?.(err)
return return
} }
...@@ -654,14 +657,18 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){ ...@@ -654,14 +657,18 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){
if (!connected) { if (!connected) {
// 出错了,返回错误 // 出错了,返回错误
// 兜底的报错 // 兜底的报错
result.errCode = 12010 let err = new UniError("uni-connectWifi",12010,"connectWifi:fail:unknown error");
result.errMsg = "connectWifi:fail:unknown error" option.fail?.(err)
option.complete?.(err)
option.fail?.(result)
option.complete?.(result)
return return
} }
let result : UniWifiResult = {
errCode: 0,
errMsg: "connectWifi:ok",
errSubject: "uni-connectWifi",
}
wifiManager.saveConfiguration() wifiManager.saveConfiguration()
//scanWifiInfo 根据 partialInfo 填充给返回字段 //scanWifiInfo 根据 partialInfo 填充给返回字段
if (option.partialInfo != null && option.partialInfo == true) { if (option.partialInfo != null && option.partialInfo == true) {
...@@ -673,9 +680,6 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){ ...@@ -673,9 +680,6 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){
result.wifi = wrapUniWifiInfoFromAndroid(scanWifiInfo) result.wifi = wrapUniWifiInfoFromAndroid(scanWifiInfo)
} }
// result.wifi = scanWifiInfo.toUTSJSON(option.partialInfo)
result.errCode = 0
result.errMsg = "connectWifi:ok"
option.success?.(result) option.success?.(result)
option.complete?.(result) option.complete?.(result)
...@@ -687,20 +691,16 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){ ...@@ -687,20 +691,16 @@ function realWifiConnect(option : WifiConnectOption,result : UniWifiResult){
@Suppress("UNUSED_PARAMETER", "DEPRECATION") @Suppress("UNUSED_PARAMETER", "DEPRECATION")
export function connectWifi(option : WifiConnectOption) { export function connectWifi(option : WifiConnectOption) {
var result : UniWifiResult = {
errCode: 12000,
errMsg: "connectWifi:fail:not invoke startWifi",
errSubject: "uni-connectWifi",
}
if (option.maunal == true) { if (option.maunal == true) {
// 指定了手动模式 // 指定了手动模式
let manunalIntent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS); let manunalIntent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS);
UTSAndroid.getUniActivity()!.startActivity(manunalIntent); UTSAndroid.getUniActivity()!.startActivity(manunalIntent);
result.errCode = 0 let result : UniWifiResult = {
result.errMsg = "connectWifi:ok" errCode: 0,
errMsg: "connectWifi:ok",
errSubject: "uni-connectWifi",
}
option.success?.(result) option.success?.(result)
option.complete?.(result) option.complete?.(result)
...@@ -719,7 +719,7 @@ export function connectWifi(option : WifiConnectOption) { ...@@ -719,7 +719,7 @@ export function connectWifi(option : WifiConnectOption) {
if(taskCount >= 5 || startWifiScaning == false){ if(taskCount >= 5 || startWifiScaning == false){
// 超过10s了。或者扫描过程结束了 // 超过10s了。或者扫描过程结束了
clearInterval(taskId) clearInterval(taskId)
realWifiConnect(option,result) realWifiConnect(option)
} }
},2000) },2000)
...@@ -727,7 +727,7 @@ export function connectWifi(option : WifiConnectOption) { ...@@ -727,7 +727,7 @@ export function connectWifi(option : WifiConnectOption) {
clearInterval(taskId) clearInterval(taskId)
}); });
}else{ }else{
realWifiConnect(option,result) realWifiConnect(option)
} }
...@@ -741,13 +741,9 @@ export function connectWifi(option : WifiConnectOption) { ...@@ -741,13 +741,9 @@ export function connectWifi(option : WifiConnectOption) {
export function stopWifi(option : WifiOption) { export function stopWifi(option : WifiOption) {
// 需要先开启wifi,才能使用后续的功能 // 需要先开启wifi,才能使用后续的功能
if (Global.mReceiver == null) { if (Global.mReceiver == null) {
var result : UniWifiResult = { let err = new UniError("uni-stopWifi",12000,"stopWifi:not init");
errCode: 12000, option.fail?.(err)
errSubject: "uni-stopWifi", option.complete?.(err)
errMsg: "stopWifi:not init"
}
option.fail?.(result)
option.complete?.(result)
return return
} }
...@@ -768,6 +764,7 @@ export function stopWifi(option : WifiOption) { ...@@ -768,6 +764,7 @@ export function stopWifi(option : WifiOption) {
errSubject: "uni-stopWifi", errSubject: "uni-stopWifi",
errMsg: "stopWifi:ok" errMsg: "stopWifi:ok"
} }
option.success?.(result) option.success?.(result)
option.complete?.(result) option.complete?.(result)
...@@ -783,16 +780,12 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) { ...@@ -783,16 +780,12 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) {
SSID: "" SSID: ""
} }
var res : UniWifiResult = {
errCode: 12000,
errMsg: "getConnectedWifi:fail:not invoke startWifi",
errSubject: "uni-getConnectedWifi",
}
if (Global.mReceiver == null) { if (Global.mReceiver == null) {
// 还没调用startWifi 提示报错 // 还没调用startWifi 提示报错
option.fail?.(res) let err = new UniError("uni-getConnectedWifi",12000,"getConnectedWifi:fail:not invoke startWifi");
option.complete?.(res) option.fail?.(err)
option.complete?.(err)
return return
} }
...@@ -800,14 +793,14 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) { ...@@ -800,14 +793,14 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) {
// 需要先校验权限,没有位置权限无法获取wifi // 需要先校验权限,没有位置权限无法获取wifi
if (ActivityCompat.checkSelfPermission(UTSAndroid.getUniActivity()!, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.checkSelfPermission(UTSAndroid.getUniActivity()!, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// 尚不具备权限,返回错误 // 尚不具备权限,返回错误
res.errCode = 12001 let err = new UniError("uni-getConnectedWifi",12001,"getConnectedWifi:permission loss");
res.errMsg = "getConnectedWifi:permission loss" option.fail?.(err)
option.complete?.(err)
option.fail?.(res)
option.complete?.(res)
return; return;
} }
const context = UTSAndroid.getAppContext(); const context = UTSAndroid.getAppContext();
if (context != null) { if (context != null) {
const wm = context.getSystemService( const wm = context.getSystemService(
...@@ -818,31 +811,37 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) { ...@@ -818,31 +811,37 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) {
const winfo = wm.getConnectionInfo(); const winfo = wm.getConnectionInfo();
wifiInfo = wrapUniWifiInfoFromConnectInfo(winfo); wifiInfo = wrapUniWifiInfoFromConnectInfo(winfo);
let res : UniWifiResult = {
errCode: 0,
errMsg: "getConnectedWifi:ok",
errSubject: "uni-getConnectedWifi",
}
// 判断一下是否wifi 关闭了 // 判断一下是否wifi 关闭了
if (option.partialInfo != null && option.partialInfo == true) { if (option.partialInfo!= null) {
let ret : UniWifiInfo = { let ret : UniWifiInfo = {
SSID: wifiInfo.SSID SSID: wifiInfo.SSID
} }
res.wifi = ret; res.wifi = ret;
} else { } else {
if (wifiInfo.BSSID == null || zeroCountNum(wifiInfo.BSSID) > 3) { if (wifiInfo.BSSID == null || zeroCountNum(wifiInfo.BSSID) > 3) {
res.errCode = 12005 let err = new UniError("uni-getConnectedWifi",12005,"getConnectedWifi:fail:wifi is disable");
res.errMsg = "getConnectedWifi:fail:wifi is disable" option.fail?.(err)
option.complete?.(err)
option.fail?.(res)
option.complete?.(res)
return return
} }
res.wifi = wifiInfo; res.wifi = wifiInfo;
} }
res.errCode = 0
res.errMsg = "getConnectedWifi:ok"
option.success?.(res) option.success?.(res)
option.complete?.(res) option.complete?.(res)
return return
} }
option.fail?.(res)
option.complete?.(res) let err = new UniError("uni-getConnectedWifi",12000,"getConnectedWifi:fail:not invoke startWifi");
option.fail?.(err)
option.complete?.(err)
} }
...@@ -114,24 +114,14 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) ...@@ -114,24 +114,14 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
option.success?.(res) option.success?.(res)
option.complete?.(res) option.complete?.(res)
}else { }else {
const res: UniWifiResult = { let err = new UniError("uni-getConnectedWifi",12010,"getConnectedWifi:system internal error");
errSubject: "uni-getConnectedWifi", option.fail?.(err)
errCode: 12010, option.complete?.(err)
errMsg: "getConnectedWifi:system internal error",
wifi: null
}
option.fail?.(res)
option.complete?.(res)
} }
}else { }else {
const res: UniWifiResult = { let err = new UniError("uni-getConnectedWifi",12010,"getConnectedWifi:system internal error");
errSubject: "uni-getConnectedWifi", option.fail?.(err)
errCode: 12010, option.complete?.(err)
errMsg: "getConnectedWifi:system internal error",
wifi: null
}
option.fail?.(res)
option.complete?.(res)
} }
} }
...@@ -183,14 +173,9 @@ export const stopWifi: StopWifi = function (option: WifiOption) { ...@@ -183,14 +173,9 @@ export const stopWifi: StopWifi = function (option: WifiOption) {
* 获取wifi列表, 在调用之前需要引导用户跳转到系统设置-WIFI设置页面,系统搜索周边wifi后app才能接收到回调 * 获取wifi列表, 在调用之前需要引导用户跳转到系统设置-WIFI设置页面,系统搜索周边wifi后app才能接收到回调
*/ */
export const getWifiList: GetWifiList = function (option: WifiOption) { export const getWifiList: GetWifiList = function (option: WifiOption) {
let res: UniWifiResult = { let err = new UniError("uni-getWifiList",12001,"getWifiList:system not support");
errSubject: "uni-getWifiList", option.fail?.(err)
errCode: 12001, option.complete?.(err)
errMsg: "getWifiList:system not support",
wifi: null
}
option.fail?.(res)
option.complete?.(res)
} }
/* 获取wifi列表的回调 /* 获取wifi列表的回调
...@@ -213,28 +198,18 @@ export const offGetWifiList: OffGetWifiList = function (callback: UniWifiCallbac ...@@ -213,28 +198,18 @@ export const offGetWifiList: OffGetWifiList = function (callback: UniWifiCallbac
*/ */
export const getConnectedWifi: GetConnectedWifi = function (option: GetConnectedWifiOptions) { export const getConnectedWifi: GetConnectedWifi = function (option: GetConnectedWifiOptions) {
if (UniWiFiModuleGloabInfo.alreadyStartWifi == false) { if (UniWiFiModuleGloabInfo.alreadyStartWifi == false) {
let res: UniWifiResult = { let err = new UniError("uni-getConnectedWifi",12000,"getConnectedWifi:not init");
errSubject: "uni-getConnectedWifi", option.fail?.(err)
errCode: 12000, option.complete?.(err)
errMsg: "getConnectedWifi:not init",
wifi: null
}
option.fail?.(res)
option.complete?.(res)
} else{ } else{
if (UIDevice.current.systemVersion >= "13.0") { if (UIDevice.current.systemVersion >= "13.0") {
requestLocationPromise((success) => { requestLocationPromise((success) => {
if (success == true) { if (success == true) {
fetchConnectedWifiWithLocationPromise(option) fetchConnectedWifiWithLocationPromise(option)
}else { }else {
let res: UniWifiResult = { let err = new UniError("uni-getConnectedWifi",12007,"getConnectedWifi:user denied");
errSubject: "uni-getConnectedWifi", option.fail?.(err)
errCode: 12007, option.complete?.(err)
errMsg: "getConnectedWifi:user denied",
wifi: null
}
option.fail?.(res)
option.complete?.(res)
} }
}) })
} else{ } else{
...@@ -247,14 +222,10 @@ export const getConnectedWifi: GetConnectedWifi = function (option: GetConnected ...@@ -247,14 +222,10 @@ export const getConnectedWifi: GetConnectedWifi = function (option: GetConnected
* 连接wifi * 连接wifi
*/ */
export const connectWifi: ConnectWifi = function (option: WifiConnectOption) { export const connectWifi: ConnectWifi = function (option: WifiConnectOption) {
let res: UniWifiResult = {
errSubject: "uni-connectWifi", let err = new UniError("uni-connectWifi",12001,"connectWifi:system not support");
errCode: 12001, option.fail?.(err)
errMsg: "connectWifi:system not support", option.complete?.(err)
wifi: null
}
option.fail?.(res)
option.complete?.(res)
} }
...@@ -290,12 +261,7 @@ export const onOffWifiConnectedWithPartialInfo: OnOffWifiConnectedWithPartialInf ...@@ -290,12 +261,7 @@ export const onOffWifiConnectedWithPartialInfo: OnOffWifiConnectedWithPartialInf
* 设置 wifiList 中 AP 的相关信息。在 onGetWifiList 回调后调用,iOS特有接口。 * 设置 wifiList 中 AP 的相关信息。在 onGetWifiList 回调后调用,iOS特有接口。
*/ */
export const setWifiList: SetWifiList = function (option: WifiOption) { export const setWifiList: SetWifiList = function (option: WifiOption) {
let res: UniWifiResult = { let err = new UniError("uni-setWifiList",12001,"setWifiList:system not support");
errSubject: "uni-setWifiList", option.fail?.(err)
errCode: 12001, option.complete?.(err)
errMsg: "setWifiList:system not support",
wifi: null
}
option.fail?.(res)
option.complete?.(res)
} }
\ No newline at end of file
/** /**
* Wifi 函数通用入参封装 * Wifi 函数通用入参封装
*/ */
export type WifiOption = { export type WifiOption = {
success?: (res: UniWifiResult) => void; success ?: (res : UniWifiResult) => void;
fail?: (res: UniWifiResult) => void; fail ?: (res : UniError) => void;
complete?: (res: UniWifiResult) => void; complete ?: (res : any) => void;
}; };
/** /**
* Wifi 链接参数封装 * Wifi 链接参数封装
*/ */
export type WifiConnectOption = { export type WifiConnectOption = {
SSID?: string; SSID ?: string;
BSSID?: string; BSSID ?: string;
password?: string; password ?: string;
maunal?: boolean; maunal ?: boolean;
partialInfo?: boolean; //ios不生效 partialInfo ?: boolean; //ios不生效
success?: (res: UniWifiResult) => void; success ?: (res : UniWifiResult) => void;
fail?: (res: UniWifiResult) => void; fail ?: (res : UniError) => void;
complete?: (res: UniWifiResult) => void; complete ?: (res : any) => void;
} }
/** /**
* 获取当前链接的wifi信息 * 获取当前链接的wifi信息
*/ */
export type GetConnectedWifiOptions = { export type GetConnectedWifiOptions = {
partialInfo?: boolean partialInfo ?: boolean
success?: (res: UniWifiResult) => void success ?: (res : UniWifiResult) => void
fail?: (res: UniWifiResult) => void fail ?: (res : UniError) => void
complete?: (res: UniWifiResult) => void complete ?: (res : any) => void
} }
/* /*
* 对外暴露的wifi信息 * 对外暴露的wifi信息
*/ */
export type UniWifiInfo = { export type UniWifiInfo = {
SSID: string; SSID : string;
BSSID?: string; BSSID ?: string;
secure?: boolean; secure ?: boolean;
signalStrength?: number; signalStrength ?: number;
frequency?: number; frequency ?: number;
} }
...@@ -47,35 +47,35 @@ export type UniWifiResult = { ...@@ -47,35 +47,35 @@ export type UniWifiResult = {
errCode : number, errCode : number,
errSubject : string, errSubject : string,
errMsg : string, errMsg : string,
wifi: UniWifiInfo | null wifi : UniWifiInfo | null
} }
export type UniWifiCallback = () => void export type UniWifiCallback = () => void
export type StartWifi = (option: WifiOption) => void export type StartWifi = (option : WifiOption) => void
export type StopWifi = (option: WifiOption) => void export type StopWifi = (option : WifiOption) => void
export type GetWifiList = (option: WifiOption) => void export type GetWifiList = (option : WifiOption) => void
export type OnGetWifiList = (callback: UniWifiCallback) => void export type OnGetWifiList = (callback : UniWifiCallback) => void
export type OffGetWifiList = (callback: UniWifiCallback) => void export type OffGetWifiList = (callback : UniWifiCallback) => void
export type GetConnectedWifi = (option: GetConnectedWifiOptions) => void export type GetConnectedWifi = (option : GetConnectedWifiOptions) => void
export type ConnectWifi = (option: WifiConnectOption) => void export type ConnectWifi = (option : WifiConnectOption) => void
export type OnWifiConnected = (callback: UniWifiCallback) => void export type OnWifiConnected = (callback : UniWifiCallback) => void
export type OnWifiConnectedWithPartialInfo = (callback: UniWifiCallback) => void export type OnWifiConnectedWithPartialInfo = (callback : UniWifiCallback) => void
export type OffWifiConnected = (callback: UniWifiCallback | null) => void export type OffWifiConnected = (callback : UniWifiCallback | null) => void
export type OnOffWifiConnectedWithPartialInfo = (callback: UniWifiCallback | null) => void export type OnOffWifiConnectedWithPartialInfo = (callback : UniWifiCallback | null) => void
export type SetWifiList = (option: WifiOption) => void export type SetWifiList = (option : WifiOption) => void
interface Uni { interface Uni {
/** /**
...@@ -99,8 +99,9 @@ interface Uni { ...@@ -99,8 +99,9 @@ interface Uni {
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { after: 'stopWifi' }
*/ */
startWifi : StartWifi, startWifi(option : WifiOption): void,
/** /**
* 关闭 Wi-Fi 模块 * 关闭 Wi-Fi 模块
* *
...@@ -122,15 +123,16 @@ interface Uni { ...@@ -122,15 +123,16 @@ interface Uni {
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { before: 'startWifi' }
*/ */
stopWifi : StopWifi, stopWifi(option : WifiOption) : void,
/** /**
* @param {WifiConnectOption} option * @param {WifiConnectOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#connectWifi * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#connectWifi
* @uniPlatform { * @uniPlatform {
* "app": { * "app": {
* "android": { * "android": {
* "osVer": "4.4.4", * "osVer": ">=4.4 && <10.0",
* "uniVer": "3.7.0", * "uniVer": "3.7.0",
* "unixVer": "3.9.0" * "unixVer": "3.9.0"
* }, * },
...@@ -163,7 +165,7 @@ interface Uni { ...@@ -163,7 +165,7 @@ interface Uni {
] ]
} }
*/ */
connectWifi : ConnectWifi, connectWifi(option : WifiConnectOption) : void,
/** /**
* 请求获取 Wi-Fi 列表。wifiList 数据会在 onGetWifiList 注册的回调中返回。 * 请求获取 Wi-Fi 列表。wifiList 数据会在 onGetWifiList 注册的回调中返回。
* @param {WifiOption} option * @param {WifiOption} option
...@@ -184,17 +186,9 @@ interface Uni { ...@@ -184,17 +186,9 @@ interface Uni {
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { * @autotest { before: 'startWifi', after: 'stopWifi' }
generated: false,
cases:[
{
before: 'startWifi',
after: 'stopWifi'
}
]
}
*/ */
getWifiList : GetWifiList, getWifiList(option : WifiOption) : void,
/** /**
* 监听获取到 Wi-Fi 列表数据事件。 * 监听获取到 Wi-Fi 列表数据事件。
* *
...@@ -216,8 +210,25 @@ interface Uni { ...@@ -216,8 +210,25 @@ interface Uni {
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
* @autotest {
generated: false,
pollution: false,
expectCallback: true,
before: 'startWifi',
after: 'onGetWifiListAfter',
cases: [
{
output: {
value: 0,
returnKey: '.wifiList.length',
jestExpectSyntax: 'toBeGreaterThan'
},
}
]
}
*/ */
onGetWifiList : OnGetWifiList, onGetWifiList(callback : UniWifiCallback) : void,
/** /**
* 移除获取到 Wi-Fi 列表数据事件的监听函数。 * 移除获取到 Wi-Fi 列表数据事件的监听函数。
* *
...@@ -239,8 +250,9 @@ interface Uni { ...@@ -239,8 +250,9 @@ interface Uni {
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/ */
offGetWifiList : OffGetWifiList, offGetWifiList(callback : UniWifiCallback) : void,
/** /**
* 获取已连接的 Wi-Fi 信息 * 获取已连接的 Wi-Fi 信息
* *
...@@ -262,8 +274,9 @@ interface Uni { ...@@ -262,8 +274,9 @@ interface Uni {
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { before: 'startWifi', after: 'stopWifi' }
*/ */
getConnectedWifi : GetConnectedWifi, getConnectedWifi(option : GetConnectedWifiOptions) : void,
/** /**
* 监听连接上 Wi-Fi 的事件 * 监听连接上 Wi-Fi 的事件
* *
...@@ -285,8 +298,9 @@ interface Uni { ...@@ -285,8 +298,9 @@ interface Uni {
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/ */
onWifiConnected : OnWifiConnected, onWifiConnected(callback : UniWifiCallback) : void,
/** /**
* 监听连接上 Wi-Fi 的事件。 * 监听连接上 Wi-Fi 的事件。
* *
...@@ -308,8 +322,9 @@ interface Uni { ...@@ -308,8 +322,9 @@ interface Uni {
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/ */
onWifiConnectedWithPartialInfo : OnWifiConnectedWithPartialInfo, onWifiConnectedWithPartialInfo(callback : UniWifiCallback) : void,
/** /**
* 移除连接上 Wi-Fi 的事件的监听函数。 * 移除连接上 Wi-Fi 的事件的监听函数。
* *
...@@ -331,8 +346,9 @@ interface Uni { ...@@ -331,8 +346,9 @@ interface Uni {
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/ */
offWifiConnected : OffWifiConnected, offWifiConnected(callback : UniWifiCallback | null) : void,
/** /**
* 移除连接上 Wi-Fi 的事件的监听函数。 * 移除连接上 Wi-Fi 的事件的监听函数。
* *
...@@ -341,20 +357,39 @@ interface Uni { ...@@ -341,20 +357,39 @@ interface Uni {
* @uniPlatform { * @uniPlatform {
* "app": { * "app": {
* "android": { * "android": {
* "osVer": "4.4.4", * "osVer": "x",
* "uniVer": "3.7.0", * "uniVer": "x",
* "unixVer": "3.9.0" * "unixVer": "x"
* }, * },
* "ios": { * "ios": {
* "osVer": "9.0", * "osVer": "x",
* "uniVer": "3.7.7", * "uniVer": "x",
* "unixVer": "3.9.0" * "unixVer": "x"
* } * }
* } * }
* } * }
* @uniVersion 3.7.7 * @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本 * @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onOffWifiConnectedWithPartialInfo(callback : UniWifiCallback | null) : void,
/**
* SetWifiList 暂未实现
*
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* }
*/ */
onOffWifiConnectedWithPartialInfo : OnOffWifiConnectedWithPartialInfo, setWifiList(option : WifiOption) : void,
setWifiList : SetWifiList,
} }
\ No newline at end of file
export function startWifi() {
return new Promise((resolve, reject) => {
uni.startWifi({
success: () => {
console.log('startWifi success');
resolve()
},
complete: () => {
console.log('startWifi fail');
resolve()
}
})
})
}
export function stopWifi() {
return new Promise((resolve, reject) => {
uni.stopWifi({
complete: resolve
})
})
}
export function onGetWifiListAfter() {
return new Promise((resolve, reject) => {
uni.getWifiList({
success() {
setTimeout(resolve, 500)
},
complete() {
stopWifi().finally(resolve)
}
})
})
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册