提交 ad61ae01 编写于 作者: DCloud_iOS_WZT's avatar DCloud_iOS_WZT

Merge branch 'dev' of https://gitcode.net/dcloud/uni-api into dev

...@@ -2,3 +2,10 @@ ...@@ -2,3 +2,10 @@
/.hbuilderx /.hbuilderx
/.vite /.vite
.DS_Store .DS_Store
env.js
jest.config.js
autotest.reporter.js
autotest.utils.js
pages/autotest/
node_modules/
vite.config.js
\ No newline at end of file
module.exports = {
testTimeout: 10000,
reporters: [
'default'
],
watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'],
moduleFileExtensions: ['js', 'json'],
rootDir: __dirname,
testMatch: ["<rootDir>/pages/**/*test.[jt]s?(x)"],
testPathIgnorePatterns: ['/node_modules/']
}
{ {
"name": "uni-api", "name" : "uni-api",
"appid": "__UNI__ED9218B", "appid" : "__UNI__ED9218B",
"description": "", "description" : "",
"versionName": "1.0.0", "versionName" : "1.0.0",
"versionCode": "100", "versionCode" : "100",
"transformPx": false, "transformPx" : false,
/* 5+App特有相关 */ /* 5+App特有相关 */
"app-plus": { "app-plus" : {
"usingComponents": true, "usingComponents" : true,
"nvueStyleCompiler": "uni-app", "nvueStyleCompiler" : "uni-app",
"compilerVersion": 3, "compilerVersion" : 3,
"splashscreen": { "splashscreen" : {
"alwaysShowBeforeRender": true, "alwaysShowBeforeRender" : true,
"waiting": true, "waiting" : true,
"autoclose": true, "autoclose" : true,
"delay": 0 "delay" : 0
}, },
/* 模块配置 */ /* 模块配置 */
"modules": {}, "modules" : {},
/* 应用发布信息 */ /* 应用发布信息 */
"distribute": { "distribute" : {
/* android打包配置 */ /* android打包配置 */
"android": { "android" : {
"permissions": [ "permissions" : [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>", "<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>", "<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>", "<uses-permission android:name=\"android.permission.VIBRATE\"/>",
...@@ -41,32 +41,32 @@ ...@@ -41,32 +41,32 @@
] ]
}, },
/* ios打包配置 */ /* ios打包配置 */
"ios": {}, "ios" : {},
/* SDK配置 */ /* SDK配置 */
"sdkConfigs": {} "sdkConfigs" : {}
} }
}, },
/* 快应用特有相关 */ /* 快应用特有相关 */
"quickapp": {}, "quickapp" : {},
/* 小程序特有相关 */ /* 小程序特有相关 */
"mp-weixin": { "mp-weixin" : {
"appid": "", "appid" : "",
"setting": { "setting" : {
"urlCheck": false "urlCheck" : false
}, },
"usingComponents": true "usingComponents" : true
}, },
"mp-alipay": { "mp-alipay" : {
"usingComponents": true "usingComponents" : true
}, },
"mp-baidu": { "mp-baidu" : {
"usingComponents": true "usingComponents" : true
}, },
"mp-toutiao": { "mp-toutiao" : {
"usingComponents": true "usingComponents" : true
}, },
"uniStatistics": { "uniStatistics" : {
"enable": false "enable" : false
}, },
"vueVersion": "2" "vueVersion" : "3"
} }
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
<button @tap="testSetUserCaptureScreen">{{setUserCaptureScreenText}}</button> <button @tap="testSetUserCaptureScreen">{{setUserCaptureScreenText}}</button>
<button @tap="testGetBatteryInfo">获取电池电量</button> <button @tap="testGetBatteryInfo">获取电池电量</button>
<button @tap="testGetBatteryInfoSync">同步获取电池电量</button>
<button @tap="testonMemoryWarning">开启内存不足告警监听</button> <button @tap="testonMemoryWarning">开启内存不足告警监听</button>
<button @tap="testoffMemoryWarning">关闭内存不足告警监听</button> <button @tap="testoffMemoryWarning">关闭内存不足告警监听</button>
...@@ -222,6 +223,12 @@ ...@@ -222,6 +223,12 @@
} }
}) })
}, },
testGetBatteryInfoSync() {
let ret = uni.getBatteryInfoSync()
console.log(ret)
},
testSetUserCaptureScreen() { testSetUserCaptureScreen() {
let flag = this.setUserCaptureScreenFlag; let flag = this.setUserCaptureScreenFlag;
uni.setUserCaptureScreen({ uni.setUserCaptureScreen({
......
{
"id": "uni-getLocation-tencent",
"displayName": "uni-getLocation-tencent",
"version": "1.0.0",
"description": "uni-getLocation-tencent",
"keywords": [
"uni-getLocation-tencent"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.11"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"uni-ext-api": {
"uni": ["getLocation"]
},
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "n",
"vue3": "y"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
\ No newline at end of file
# uts-tencentgeolocation腾讯定位插件使用文档
## Android 平台
1. 申请腾讯地图key
[申请网址](https://lbs.qq.com/mobile/androidMapSDK/developerGuide/getKey)
2. 配置key到插件中
修改项目根目录下 AndroidManifest.xml
`<meta-data android:name="TencentMapSDK" android:value="您申请的Key" />`
3. 打包自定义基座
注意将`uts-tencentgeolocation/utssdk/app-android/libs/androix-core-1.0.0.jar`先移到其他目录。
4. 运行自定义基座
注意打包自定义基座后将androix-core-1.0.0.jar移回原位,然后真机运行自定义基座。这个临时的移出移入问题后续会升级解决,详见uts插件开发文档的[临时注意](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#tempnotice)
## iOS 平台
1.申请腾讯地图key
[申请网址](https://lbs.qq.com/mobile/androidMapSDK/developerGuide/getKey)
2.配置key到插件中
将申请的key配置到插件目录下 app-ios -> info.plist 中 TencentLBSAPIKey 对应的值
```xml
<key>TencentLBSAPIKey</key>
<string>您申请的Key</string>
```
3.配置访问位置权限描述信息
选中工程中的 manifest.json -> App权限配置 -> iOS隐私信息访问的许可描述,分别配置下列权限描述信息
- NSLocationAlwaysUsageDescription
- NSLocationWhenInUseUsageDescription
- NSLocationAlwaysAndWhenInUseUsageDescription
4.制作自定义基座运行后生效
## 相关开发文档
- [UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
- [UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="io.dcloud.nativeresouce">
<!--permissions-->
<!-- 通过GPS得到精确位置 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- 通过网络得到粗略位置 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- 访问网络,某些位置信息需要从网络服务器获取 -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- 访问WiFi状态,需要WiFi信息用于网络定位 -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!-- 修改WiFi状态,发起WiFi扫描, 需要WiFi信息用于网络定位 -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<!-- 访问网络状态, 检测网络的可用性,需要网络运营商相关信息用于网络定位 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- 访问网络的变化, 需要某些信息用于网络定位 -->
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<!-- 蓝牙扫描权限 -->
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<!-- 前台service权限 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<!-- 后台定位权限 -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<!-- A-GPS辅助定位权限,方便GPS快速准确定位 -->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
</manifest>
{
"dependencies": [
"com.tencent.map.geolocation:TencentLocationSdk-openplatform:7.3.0"
],
"minSdkVersion": 21
}
import {
UTSAndroid
} from "io.dcloud.uts";
import ActivityCompat from "androidx.core.app.ActivityCompat";
import Manifest from "android.Manifest";
import Looper from "android.os.Looper";
import TencentLocationManager from "com.tencent.map.geolocation.TencentLocationManager";
import TencentLocationListener from "com.tencent.map.geolocation.TencentLocationListener";
import TencentLocation from "com.tencent.map.geolocation.TencentLocation";
import TencentLocationRequest from "com.tencent.map.geolocation.TencentLocationRequest";
import PackageManager from "android.content.pm.PackageManager";
import Class from 'java.lang.Class';
import Exception from 'java.lang.Exception';
import { GetLocation, GetLocationOptions, GetLocationSuccess,GetLocationFail } from "../interface.uts"
export const getLocation : GetLocation = function (options : GetLocationOptions) {
if(!checkHasIntegration()){
// 当前没有集成腾讯sdk,提示需要打包
let ret : GetLocationFail = {
errCode: -10,
errMsg: "需要打自定义基座",
errSubject: "uni-getLocation-tencent"
}
options.fail?.(ret)
options.complete?.(ret)
return;
}
if (!checkLocationConfig()) {
let ret : GetLocationFail = {
errCode: -20,
errMsg: "未通过配置预校验,通常是app key 配置错误",
errSubject: "uni-getLocation-tencent"
}
options.fail?.(ret)
options.complete?.(ret)
return;
}
/**
* 准备权限
*/
let permissionNeed : string[] = utsArrayOf("android.permission.ACCESS_FINE_LOCATION");
UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, permissionNeed, function (allRight:boolean,_grantedList:string[]) {
if (allRight) {
// 交给目前的location 引擎,真实执行
getLocationImpl(options)
}
}, function (_doNotAskAgain:boolean,_grantedList:string[]) {
console.log("用户拒绝了部分权限:")
let ret : GetLocationFail = {
errCode: -30,
errMsg: "permission missed.",
errSubject: "uni-getLocation-tencent"
}
options.fail?.(ret)
options.complete?.(ret)
})
}
/****************************************内部功能实现****************************************************/
/**
* 定位监听结果包装类
*/
class LocationOptionsWapper {
hostOption : GetLocationOptions;
constructor(option : GetLocationOptions) {
this.hostOption = option
}
onLocationChanged(location : TencentLocation, _error : Int,
_reason : string) {
let ret : GetLocationSuccess = {
latitude: location.latitude,
longitude: location.longitude,
speed: 0,
accuracy: location.accuracy,
altitude: location.altitude,
verticalAccuracy: 0,
horizontalAccuracy: location.accuracy,
address: location.address
}
this.hostOption.success?.(ret)
// 包装数据结构返回
}
onStatusUpdate(_name : string, _status : Int, _desc : string) {
// 定位状态发生变化
}
};
/**
* Tencent 定位监听实现类
*/
class SingleLocationListener extends TencentLocationListener {
hostOptionWraper : LocationOptionsWapper;
constructor(option : LocationOptionsWapper) {
super();
this.hostOptionWraper = option
}
override onLocationChanged(location : TencentLocation, error : Int,
reason : string) : void {
this.hostOptionWraper.onLocationChanged(location, error, reason);
}
override onStatusUpdate(name : string, status : Int, desc : string) : void {
this.hostOptionWraper.onStatusUpdate(name, status, desc);
}
}
/**
* 判断当前的基座是否已经集成了sdk, 即是否是自定义基座
*/
function checkHasIntegration() : boolean {
let hasIntegration = true
try {
let xClass = Class.forName("com.tencent.map.geolocation.TencentLocationListener")
} catch (e : Exception) {
hasIntegration = false;
}
if (!hasIntegration) {
return false;
}
return true
}
/**
* 检查定位的相关配置是否正确
*/
function checkLocationConfig() : boolean {
let packageName = UTSAndroid.getAppContext()!.getPackageName();
let appInfo = UTSAndroid.getAppContext()!.getPackageManager()!.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
let metaData = appInfo.metaData
if (metaData == null) {
return false;
}
let adId = metaData.getString("TencentMapSDK")
if (adId == null) {
return false;
}
let splitArray = adId!.split("-")
let keyCharNum = splitArray.size
if (keyCharNum > 5) {
// 存在超过5个-,说明是符合规则的appkey
return true;
}
// 不符合校验规则,打回
return false;
}
/**
* 腾讯地图获取定位信息
* 参考文档:https://lbs.qq.com/mobile/androidLocationSDK/androidGeoGuide/androidGeoAdapt
*/
function getLocationImpl(locationOptions : GetLocationOptions) {
if(locationOptions.type != null && locationOptions.type!.toUpperCase() != 'GCJ-02' && locationOptions.type!.toUpperCase() != 'GCJ02'){
// 腾讯定位只支持GCJ-02,如果不是则报错
let ret : GetLocationFail = {
errCode: -1,
errMsg: "GCJ-02 support only.",
errSubject: "uni-getLocation-tencent"
}
locationOptions.fail?.(ret)
locationOptions.complete?.(ret)
return
}
let mLocationManager = TencentLocationManager.getInstance(UTSAndroid.getAppContext());
// 定位监听器封装
let locationOptionWrapper = new LocationOptionsWapper(locationOptions);
let mLocationListener = new SingleLocationListener(locationOptionWrapper);
// 发起单次请求
let locationRequest = TencentLocationRequest.create()
// 是否需要逆地理编码
if (locationOptions.geocode != null && locationOptions.geocode == true) {
locationRequest.setRequestLevel(TencentLocationRequest.REQUEST_LEVEL_NAME);
} else {
locationRequest.setRequestLevel(TencentLocationRequest.REQUEST_LEVEL_GEO);
}
// 是否开启了高精度
if (locationOptions.isHighAccuracy != null && locationOptions.isHighAccuracy == true) {
locationRequest.setAllowGPS(true)
}
/**
* 高度信息,腾讯没有明确的api设置
*/
if (locationOptions.altitude != null && locationOptions.altitude == true) {
locationRequest.setAllowGPS(true)
}
mLocationManager.requestSingleFreshLocation(locationRequest, mLocationListener, Looper.getMainLooper());
}
export interface Uni {
/**
* 获取当前的地理位置、速度
*
* @tutorial http://uniapp.dcloud.io/api/location/location?id=getlocation
*/
getLocation: GetLocation;
}
export type GetLocation = (options: GetLocationOptions) => void;
export type GetLocationSuccess = {
/**
* 纬度,浮点数,范围为-90~90,负数表示南纬
*/
latitude: number,
/**
* 经度,范围为-180~180,负数表示西经
*/
longitude: number,
/**
* 速度,浮点数,单位m/s
*/
speed: number,
/**
* 位置的精确度
*/
accuracy: number,
/**
* 高度,单位 m
*/
altitude: number,
/**
* 垂直精度,单位 m(Android 无法获取,返回 0)
*/
verticalAccuracy: number,
/**
* 水平精度,单位 m
*/
horizontalAccuracy: number,
/**
* 地址信息
*/
address: any | null
};
type GetLocationSuccessCallback = (result: GetLocationSuccess) => void;
export type GetLocationFail = UniError;
type UniError = {
errSubject: string,
errCode: number,
errMsg: string,
data: object | null,
cause: any | null
};
type GetLocationFailCallback = (result: GetLocationFail) => void;
type GetLocationComplete = any;
type GetLocationCompleteCallback = (result: GetLocationComplete) => void;
export type GetLocationOptions = {
/**
* 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于uni.openLocation的坐标
*/
type?: string | null,
/**
* 传入 true 会返回高度信息,由于获取高度需要较高精确度,会减慢接口返回速度
* @type boolean
*/
altitude?: boolean | null,
/**
* 传入 true 会解析地址
* @type boolean
*/
geocode?: boolean | null,
/**
* 高精度定位超时时间(ms),指定时间内返回最高精度,该值3000ms以上高精度定位才有效果
*/
highAccuracyExpireTime?: number | null,
/**
* 开启高精度定位
* @type boolean
*/
isHighAccuracy?: boolean | null,
/**
* 接口调用成功的回调函数
*/
success?: GetLocationSuccessCallback | null,
/**
* 接口调用失败的回调函数
*/
fail?: GetLocationFailCallback | null,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete?: GetLocationCompleteCallback | null
};
...@@ -32,7 +32,12 @@ ...@@ -32,7 +32,12 @@
}, },
"uni_modules": { "uni_modules": {
"uni-ext-api": { "uni-ext-api": {
"uni": ["getBatteryInfo"] "uni": {
"getBatteryInfo": "getBatteryInfo",
"getBatteryInfoSync": {
"web": false
}
}
}, },
"dependencies": [], "dependencies": [],
"encrypt": [], "encrypt": [],
......
...@@ -2,8 +2,11 @@ import Context from "android.content.Context"; ...@@ -2,8 +2,11 @@ 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 { UTSAndroid } from "io.dcloud.uts";
import { GetBatteryInfo, GetBatteryInfoSuccess, GetBatteryInfoFail, GetBatteryInfoOptions } from '../interface.uts' import { GetBatteryInfo, GetBatteryInfoSuccess, GetBatteryInfoFail, GetBatteryInfoResult,GetBatteryInfoSync } from '../interface.uts'
/**
* 异步获取电量
* @param {Object} options
*/
export const getBatteryInfo : GetBatteryInfo = function (options) { export const getBatteryInfo : GetBatteryInfo = function (options) {
const context = UTSAndroid.getAppContext(); const context = UTSAndroid.getAppContext();
if (context != null) { if (context != null) {
...@@ -31,3 +34,36 @@ export const getBatteryInfo : GetBatteryInfo = function (options) { ...@@ -31,3 +34,36 @@ export const getBatteryInfo : GetBatteryInfo = function (options) {
options.complete?.(res) options.complete?.(res)
} }
} }
/**
* 同步获取电量示例
*/
export const getBatteryInfoSync : GetBatteryInfoSync = function (): GetBatteryInfoResult {
const context = UTSAndroid.getAppContext();
if (context != null) {
const manager = context.getSystemService(
Context.BATTERY_SERVICE
) as BatteryManager;
const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY
);
const res : GetBatteryInfoResult = {
level: level,
isCharging: manager.isCharging()
};
return res;
} else {
/**
* 无有效上下文
*/
const res : GetBatteryInfoResult = {
level: -1,
isCharging: false
};
return res;
}
}
\ 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';
/** /**
* 导出 获取电量方法 * 导出 获取电量方法
...@@ -21,3 +21,16 @@ export const getBatteryInfo : GetBatteryInfo = function (options) { ...@@ -21,3 +21,16 @@ export const getBatteryInfo : GetBatteryInfo = function (options) {
options.success?.(res); options.success?.(res);
options.complete?.(res); options.complete?.(res);
} }
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;
}
\ No newline at end of file
...@@ -46,6 +46,17 @@ export type GetBatteryInfoOptions = { ...@@ -46,6 +46,17 @@ export type GetBatteryInfoOptions = {
complete ?: (res : any) => void complete ?: (res : any) => void
} }
export type GetBatteryInfoResult = {
/**
* 设备电量,范围1 - 100
*/
level : number,
/**
* 是否正在充电中
*/
isCharging : boolean
}
/** /**
* 获取电量信息 * 获取电量信息
* @param {GetBatteryInfoOptions} options * @param {GetBatteryInfoOptions} options
...@@ -59,3 +70,70 @@ export type GetBatteryInfoOptions = { ...@@ -59,3 +70,70 @@ export type GetBatteryInfoOptions = {
* @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 {
/**
* 获取电池电量信息
* @description 获取电池电量信息
* @param {GetBatteryInfoOptions} options
* @example
* ```typescript
* uni.getBatteryInfo({
* success(res) {
* console.log(res);
* }
* })
* ```
* @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版本
*
*/
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
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": [],
......
import { UTSAndroid } from "io.dcloud.uts" import { UTSAndroid } from "io.dcloud.uts"
import { OnMemoryWarning, OffMemoryWarning } from "../interface.uts"
let listeners: UTSCallback[] = [] let listeners: UTSCallback[] = []
...@@ -14,7 +14,7 @@ const onAppTrimMemoryListener = (ret: number) => { ...@@ -14,7 +14,7 @@ const onAppTrimMemoryListener = (ret: number) => {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
export function onMemoryWarning(callback: UTSCallback) { export const onMemoryWarning : OnMemoryWarning = function (callback: UTSCallback) {
if (listeners.length == 0) { if (listeners.length == 0) {
// 仅首次执行底层的实际监听 // 仅首次执行底层的实际监听
UTSAndroid.onAppTrimMemory(onAppTrimMemoryListener) UTSAndroid.onAppTrimMemory(onAppTrimMemoryListener)
...@@ -28,7 +28,7 @@ export function onMemoryWarning(callback: UTSCallback) { ...@@ -28,7 +28,7 @@ export function onMemoryWarning(callback: UTSCallback) {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
export function offMemoryWarning(callback: UTSCallback | null) { export const offMemoryWarning : OffMemoryWarning = function (callback: UTSCallback | null) {
if(callback == null){ if(callback == null){
// 清除全部回调 // 清除全部回调
......
import { NotificationCenter } from 'Foundation'; import { NotificationCenter } from 'Foundation';
import { UIApplication } from "UIKit" import { UIApplication } from "UIKit"
import { Selector } from "ObjectiveC" import { Selector } from "ObjectiveC"
import { OnMemoryWarning, OffMemoryWarning } from "../interface.uts"
class MemoryWarningTool { class MemoryWarningTool {
static listeners: UTSCallback[] = [] static listeners: UTSCallback[] = []
...@@ -45,12 +46,13 @@ class MemoryWarningTool { ...@@ -45,12 +46,13 @@ class MemoryWarningTool {
} }
} }
// 开启监听内存警告 // 开启监听内存警告
export function onMemoryWarning(callback: UTSCallback) { export const onMemoryWarning : OnMemoryWarning = function (callback: UTSCallback) {
MemoryWarningTool.listenMemoryWarning(callback) MemoryWarningTool.listenMemoryWarning(callback)
} }
// 关闭监听内存警告 // 关闭监听内存警告
export function offMemoryWarning(callback: UTSCallback | null) { export const offMemoryWarning : OffMemoryWarning = function (callback: UTSCallback | null) {
MemoryWarningTool.removeListen(callback) MemoryWarningTool.removeListen(callback)
} }
\ No newline at end of file
export type OnMemoryWarning = (callback: UTSCallback) => void
export type OffMemoryWarning = (callback : UTSCallback | null) => void
export interface Uni {
/**
* 开启监听内存警告
*
* @param {UTSCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/memory.html#onmemorywarning
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onMemoryWarning : OnMemoryWarning,
/**
* 取消监听内存不足告警事件
*
* @param {UTSCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/memory.html#offmemorywarning
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
offMemoryWarning : OffMemoryWarning
}
\ 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
}) })
} }
/** /**
......
...@@ -13,26 +13,8 @@ export type OnUserCaptureScreenCallbackResult = { ...@@ -13,26 +13,8 @@ export type OnUserCaptureScreenCallbackResult = {
*/ */
export type UserCaptureScreenCallback = (res : OnUserCaptureScreenCallbackResult) => void export type UserCaptureScreenCallback = (res : OnUserCaptureScreenCallbackResult) => void
/**
* uni.onUserCaptureScreen函数定义
* 开启截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^4.4
* @since 3.7.7
*/
export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/**
* uni.offUserCaptureScreen函数定义
* 关闭截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^4.4
* @since 3.7.7
*/
export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/** /**
...@@ -102,21 +84,78 @@ export type SetUserCaptureScreenOptions = { ...@@ -102,21 +84,78 @@ export type SetUserCaptureScreenOptions = {
complete ?: SetUserCaptureScreenCompleteCallback complete ?: SetUserCaptureScreenCompleteCallback
} }
export type SetUserCaptureScreen = (options : SetUserCaptureScreenOptions) => void
/** export interface Uni {
* * uni.setUserCaptureScreen函数定义 /**
* 开启截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onUserCaptureScreen : OnUserCaptureScreen,
/**
* 关闭截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
offUserCaptureScreen : OffUserCaptureScreen,
/**
* 设置防截屏 * 设置防截屏
* *
* @param {SetUserCaptureScreenOptions} options * @param {SetUserCaptureScreenOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen * @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen
* @platforms APP-IOS = ^13.0,APP-ANDROID = ^4.4 * @uniPlatform {
* @since 3.7.7 * "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "13.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
*/ */
export type SetUserCaptureScreen = (options : SetUserCaptureScreenOptions) => void
export interface Uni {
onUserCaptureScreen : OnUserCaptureScreen,
offUserCaptureScreen : OffUserCaptureScreen,
setUserCaptureScreen : SetUserCaptureScreen setUserCaptureScreen : SetUserCaptureScreen
} }
\ 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": [],
......
...@@ -378,7 +378,7 @@ export function startWifi(option : WifiOption) { ...@@ -378,7 +378,7 @@ export function startWifi(option : WifiOption) {
// 检查权限 // 检查权限
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) ActivityCompat.requestPermissions(UTSAndroid.getUniActivity()!, permissionWifi, requestCode.toInt())
// 尚不具备权限,返回错误 // 尚不具备权限,返回错误
option.fail?.(result) option.fail?.(result)
option.complete?.(result) option.complete?.(result)
......
{ {
"frameworks": [ "frameworks": [
"CoreLocation", "CoreLocation.framework",
"SystemConfiguration" "SystemConfiguration.framework"
], ],
"validArchitectures": [ "validArchitectures": [
"arm64", "armv7" ] "arm64", "armv7"
]
} }
\ 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 : UniWifiResult) => void;
complete?: (res: UniWifiResult) => void; complete ?: (res : UniWifiResult) => 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 : UniWifiResult) => void;
complete?: (res: UniWifiResult) => void; complete ?: (res : UniWifiResult) => 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 : UniWifiResult) => void
complete?: (res: UniWifiResult) => void complete ?: (res : UniWifiResult) => 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,40 +47,104 @@ export type UniWifiResult = { ...@@ -47,40 +47,104 @@ 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 {
/**
* 初始化Wi-Fi模块
*
* @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#startwifi
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { after: 'stopWifi' }
*/
startWifi : StartWifi, startWifi : StartWifi,
/**
* 关闭 Wi-Fi 模块
*
* @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#stopwifi
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { before: 'startWifi' }
*/
stopWifi : StopWifi, stopWifi : StopWifi,
/** /**
* @param {WifiConnectOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#connectWifi
* @uniPlatform {
* "app": {
* "android": {
* "osVer": ">=4.4 && <10.0",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { * @autotest {
generated: false, generated: false,
pollution: false, pollution: false,
...@@ -101,25 +165,231 @@ interface Uni { ...@@ -101,25 +165,231 @@ interface Uni {
] ]
} }
*/ */
connectWifi: ConnectWifi, connectWifi : ConnectWifi,
/**
* 请求获取 Wi-Fi 列表。wifiList 数据会在 onGetWifiList 注册的回调中返回。
* @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#getWifiList
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { before: 'startWifi', after: 'stopWifi' }
*/
getWifiList : GetWifiList,
/** /**
* 监听获取到 Wi-Fi 列表数据事件。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onGetWifiList
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
* @autotest { * @autotest {
generated: false, generated: false,
cases:[ pollution: false,
{ expectCallback: true,
before: 'startWifi', before: 'startWifi',
after: 'stopWifi' after: 'onGetWifiListAfter',
cases: [
{
output: {
value: 0,
returnKey: '.wifiList.length',
jestExpectSyntax: 'toBeGreaterThan'
},
} }
] ]
} }
*/ */
getWifiList : GetWifiList,
onGetWifiList : OnGetWifiList, onGetWifiList : OnGetWifiList,
/**
* 移除获取到 Wi-Fi 列表数据事件的监听函数。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offGetWifiList
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
offGetWifiList : OffGetWifiList, offGetWifiList : OffGetWifiList,
/**
* 获取已连接的 Wi-Fi 信息
*
* @param {GetConnectedWifiOptions} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#getConnectedWifi
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { before: 'startWifi', after: 'stopWifi' }
*/
getConnectedWifi : GetConnectedWifi, getConnectedWifi : GetConnectedWifi,
/**
* 监听连接上 Wi-Fi 的事件
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnected
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onWifiConnected : OnWifiConnected, onWifiConnected : OnWifiConnected,
/**
* 监听连接上 Wi-Fi 的事件。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onWifiConnectedWithPartialInfo : OnWifiConnectedWithPartialInfo, onWifiConnectedWithPartialInfo : OnWifiConnectedWithPartialInfo,
/**
* 移除连接上 Wi-Fi 的事件的监听函数。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnected
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
offWifiConnected : OffWifiConnected, offWifiConnected : OffWifiConnected,
/**
* 移除连接上 Wi-Fi 的事件的监听函数。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onOffWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onOffWifiConnectedWithPartialInfo : OnOffWifiConnectedWithPartialInfo, onOffWifiConnectedWithPartialInfo : OnOffWifiConnectedWithPartialInfo,
/**
* SetWifiList 暂未实现
*
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* }
*/
setWifiList : SetWifiList, setWifiList : SetWifiList,
} }
\ No newline at end of file
function startWifi() { export function startWifi() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.startWifi({ uni.startWifi({
success: () => { success: () => {
console.log('startWifi success'); console.log('startWifi success');
resolve() resolve()
}, },
fail: () => { complete: () => {
console.log('startWifi fail'); console.log('startWifi fail');
reject() resolve()
} }
}) })
}) })
} }
function stopWifi() { export function stopWifi() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.stopWifi({ uni.stopWifi({
success: () => { complete: resolve
console.log('stopWifi success');
resolve()
},
fail: () => {
console.log('stopWifi success');
fail()
}
}) })
}) })
} }
export function onGetWifiListAfter() {
module.exports = { return new Promise((resolve, reject) => {
startWifi, uni.getWifiList({
stopWifi 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.
先完成此消息的编辑!
想要评论请 注册