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

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

# Conflicts:
#	uni_modules/uni-usercapturescreen/package.json
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/']
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"style": { "style": {
"navigationBarTitleText": "uni-app" "navigationBarTitleText": "uni-app"
} }
} }
], ],
"globalStyle": { "globalStyle": {
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black",
......
<template> <template>
<view class="content"> <view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{title}}</text> <button @tap="testStartWifi" style="width: 100%;">初始化wifi模块</button>
</view> <button @tap="testGetWifiList" style="width: 100%;">获取当前wifi列表</button>
<button @tap="testOffGetWifiList" style="width: 100%;">移除wifi列表监听</button>
<button @tap="testGetConnnectWifi" style="width: 100%;">获取当前连接的wifi</button>
<button @tap="testConnnectWifi" style="width: 100%;">链接wifi</button>
<button @tap="testStopWifi" style="width: 100%;">关闭wifi模块</button>
<button @tap="onGetWifiList2_assert0" style="width: 100%;">onGetWifiList2_assert0</button>
<button @tap="testScreenShotListen">开启截屏监听</button> <button @tap="testScreenShotListen">开启截屏监听</button>
<button @tap="testScreenShotOff">关闭截屏监听</button> <button @tap="testScreenShotOff">关闭截屏监听</button>
<button @tap="testSetUserCaptureScreen">{{setUserCaptureScreenText}}</button> <button @tap="testSetUserCaptureScreen">{{setUserCaptureScreenText}}</button>
...@@ -12,11 +19,7 @@ ...@@ -12,11 +19,7 @@
<button @tap="testonMemoryWarning">开启内存不足告警监听</button> <button @tap="testonMemoryWarning">开启内存不足告警监听</button>
<button @tap="testoffMemoryWarning">关闭内存不足告警监听</button> <button @tap="testoffMemoryWarning">关闭内存不足告警监听</button>
<button @tap="testStartWifi">初始化wifi模块</button>
<button @tap="testGetWifiList">获取当前wifi列表</button>
<button @tap="testGetConnnectWifi">获取当前连接的wifi</button>
<button @tap="testConnnectWifi">链接wifi</button>
<button @tap="testStopWifi">关闭wifi模块</button>
</view> </view>
</template> </template>
...@@ -25,7 +28,6 @@ ...@@ -25,7 +28,6 @@
export default { export default {
data() { data() {
return { return {
title: 'Hello',
memListener:null, memListener:null,
setUserCaptureScreenFlag: false, setUserCaptureScreenFlag: false,
setUserCaptureScreenText: '禁止截屏', setUserCaptureScreenText: '禁止截屏',
...@@ -39,16 +41,49 @@ ...@@ -39,16 +41,49 @@
onMemoryWarning:function(res){ onMemoryWarning:function(res){
console.log(res); console.log(res);
}, },
fn:function(res){
console.log(res)
},
onGetWifiList2_assert0() {
const fn = res => console.log('onGetWifiList res', res)
uni.startWifi({success(){
uni.onGetWifiList(fn)
uni.getWifiList({
success() {
console.log('getWifiList success');
uni.offGetWifiList(fn)
uni.stopWifi({
success() {},
fail(e) {
console.log("stopWifi fail: ",e);
}
})
}
})
}})
},
testConnnectWifi(){ testConnnectWifi(){
uni.connectWifi({ uni.startWifi({
maunal:false, success:(res)=> {
SSID:"Xiaomi_20D0", console.log("success: " + JSON.stringify(res));
password:"BBBB", // uni.connectWifi({
complete:(res)=>{ // maunal:false,
console.log(res); // SSID:"Xiaomi_20D0",
// password:"BBB111",
// complete:(res)=>{
// console.log(res);
// }
// });
},fail:(res)=>{
console.log("fail: " + JSON.stringify(res));
},complete:(res)=>{
console.log("complete: " + JSON.stringify(res));
} }
}); })
}, },
testGetConnnectWifi(){ testGetConnnectWifi(){
...@@ -97,6 +132,9 @@ ...@@ -97,6 +132,9 @@
}) })
}, },
testStopWifi() { testStopWifi() {
uni.offWifiConnected()
uni.offWifiConnectedWithPartialInfo()
uni.stopWifi({ uni.stopWifi({
success:(res)=> { success:(res)=> {
console.log("success: " + JSON.stringify(res)); console.log("success: " + JSON.stringify(res));
...@@ -120,6 +158,13 @@ ...@@ -120,6 +158,13 @@
}) })
}, },
testOffGetWifiList(){
uni.offGetWifiList()
},
testonMemoryWarning() { testonMemoryWarning() {
uni.onMemoryWarning(this.onMemoryWarning) uni.onMemoryWarning(this.onMemoryWarning)
uni.showToast({ uni.showToast({
......
## 1.0.4(2023-03-24)
新增开启/关闭防截屏功能
## 1.0.3(2023-03-17)
修复android平台 部分场景下js可能报错的问题
## 1.0.2(2023-03-16)
修复Android平台在小米设备无法监听的问题 修复Android平台调用uni.onUserCaptureScreen必然会触发回调的问题
## 1.0.1(2022-10-27) ## 1.0.1(2022-10-27)
修改插件描述 修改插件描述
## 1.0.0(2022-10-26) ## 1.0.0(2022-10-26)
......
{ {
"id": "uni-usercapturescreen", "id": "uni-usercapturescreen",
"displayName": "uni-usercapturescreen", "displayName": "uni-usercapturescreen",
"version": "1.0.1", "version": "1.0.4",
"description": "用户主动截屏事件监听", "description": "用户主动截屏事件监听",
"keywords": [ "keywords": [
"截屏" "截屏"
], ],
"repository": "", "repository": "",
"engines": { "engines": {
"HBuilderX": "^3.6.8" "HBuilderX": "^3.7.7"
}, },
"dcloudext": { "dcloudext": {
"type": "uts", "type": "uts",
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
}, },
"client": { "client": {
"Vue": { "Vue": {
"vue2": "y", "vue2": "n",
"vue3": "y" "vue3": "y"
}, },
"App": { "App": {
......
...@@ -13,3 +13,9 @@ ...@@ -13,3 +13,9 @@
用户主动截屏事件。取消事件监听。 用户主动截屏事件。取消事件监听。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen](https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen) > 使用文档:[https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen](https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen)
### uni.setUserCaptureScreen
开启/关闭防截屏。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen](https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen)
...@@ -19,8 +19,8 @@ export type UserCaptureScreenCallback = (res : OnUserCaptureScreenCallbackResult ...@@ -19,8 +19,8 @@ export type UserCaptureScreenCallback = (res : OnUserCaptureScreenCallbackResult
* *
* @param {UserCaptureScreenCallback} callback * @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen * @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^19 * @platforms APP-IOS = ^9.0,APP-ANDROID = ^4.4
* @since 3.6.8 * @since 3.7.7
*/ */
export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
...@@ -30,8 +30,8 @@ export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) ...@@ -30,8 +30,8 @@ export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null)
* *
* @param {UserCaptureScreenCallback} callback * @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen * @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^19 * @platforms APP-IOS = ^9.0,APP-ANDROID = ^4.4
* @since 3.6.8 * @since 3.7.7
*/ */
export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
...@@ -47,8 +47,6 @@ export type SetUserCaptureScreenSuccess = { ...@@ -47,8 +47,6 @@ export type SetUserCaptureScreenSuccess = {
export type SetUserCaptureScreenFail = { export type SetUserCaptureScreenFail = {
/** /**
* 错误码 * 错误码
* 0:成功
* -1:permission denied
* 12001:system not support * 12001:system not support
* 12010:system internal error * 12010:system internal error
*/ */
...@@ -112,12 +110,12 @@ export type SetUserCaptureScreenOptions = { ...@@ -112,12 +110,12 @@ export type SetUserCaptureScreenOptions = {
* *
* @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 = ^19 * @platforms APP-IOS = ^13.0,APP-ANDROID = ^4.4
* @since 3.7.3 * @since 3.7.7
*/ */
export type SetUserCaptureScreen = (options : SetUserCaptureScreenOptions) => void export type SetUserCaptureScreen = (options : SetUserCaptureScreenOptions) => void
interface uni { export interface Uni {
onUserCaptureScreen : OnUserCaptureScreen, onUserCaptureScreen : OnUserCaptureScreen,
offUserCaptureScreen : OffUserCaptureScreen, offUserCaptureScreen : OffUserCaptureScreen,
setUserCaptureScreen : SetUserCaptureScreen setUserCaptureScreen : SetUserCaptureScreen
......
...@@ -3,60 +3,7 @@ import { CaptiveNetwork, kCNNetworkInfoKeySSID, kCNNetworkInfoKeyBSSID } from 'S ...@@ -3,60 +3,7 @@ import { CaptiveNetwork, kCNNetworkInfoKeySSID, kCNNetworkInfoKeyBSSID } from 'S
import { NSArray, NSDictionary } from 'Foundation'; import { NSArray, NSDictionary } from 'Foundation';
import { CFString } from 'CoreFoundation'; import { CFString } from 'CoreFoundation';
import { UIDevice } from 'UIKit'; import { UIDevice } from 'UIKit';
import { WifiOption, WifiConnectOption, GetConnectedWifiOptions, UniWifiInfo, UniWifiResult, UniWifiCallback, StartWifi, StopWifi, GetWifiList, OnGetWifiList, OffGetWifiList, GetConnectedWifi, ConnectWifi, OnWifiConnected, OnWifiConnectedWithPartialInfo, OffWifiConnected, OnOffWifiConnectedWithPartialInfo, SetWifiList } from "../interface.uts"
/**
* Wifi 函数通用入参封装
*/
type WifiOption = {
success?: (res: UniWifiResult) => void;
fail?: (res: UniWifiResult) => void;
complete?: (res: UniWifiResult) => void;
};
/**
* Wifi 链接参数封装
*/
type WifiConnectOption = {
SSID?: string;
BSSID?: string;
password?: string;
maunal?: boolean;
partialInfo?: boolean; //ios不生效
success?: (res: UniWifiResult) => void;
fail?: (res: UniWifiResult) => void;
complete?: (res: UniWifiResult) => void;
}
/**
* 获取当前链接的wifi信息
*/
type GetConnectedWifiOptions = {
partialInfo?: boolean
success?: (res: UniWifiResult) => void
fail?: (res: UniWifiResult) => void
complete?: (res: UniWifiResult) => void
}
/*
* 对外暴露的wifi信息
*/
type UniWifiInfo = {
SSID: string;
BSSID: string;
secure: boolean;
signalStrength: number;
frequency: number;
}
type UniWifiResult = {
errCode : number,
errSubject : string,
errMsg : string,
wifi: UniWifiInfo | null
}
type UniWifiCallback = () => void
/* /*
* 系统定位权限获取类 * 系统定位权限获取类
...@@ -135,7 +82,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) ...@@ -135,7 +82,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
let list = arr! as NSArray let list = arr! as NSArray
let index = 0 let index = 0
while (index < list.count) { while (index < list.count) {
let item = list[index] let item = list[index]
let interfaceName = item as string let interfaceName = item as string
let dic = CNCopyCurrentNetworkInfo(interfaceName as CFString) let dic = CNCopyCurrentNetworkInfo(interfaceName as CFString)
if (dic != null) { if (dic != null) {
...@@ -157,7 +104,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) ...@@ -157,7 +104,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
index++ index++
} }
if (wifiInfo.BSSID.length > 0 && wifiInfo.SSID.length > 0) { if (wifiInfo.BSSID!.length > 0 && wifiInfo.SSID.length > 0) {
let res: UniWifiResult = { let res: UniWifiResult = {
errSubject: "uni-getConnectedWifi", errSubject: "uni-getConnectedWifi",
errCode: 0, errCode: 0,
...@@ -204,7 +151,7 @@ class UniWiFiModuleGloabInfo { ...@@ -204,7 +151,7 @@ class UniWiFiModuleGloabInfo {
/* /*
* 初始化wifi模块 * 初始化wifi模块
*/ */
export function startWifi(option: WifiOption) { export const startWifi: StartWifi = function (option: WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = true UniWiFiModuleGloabInfo.alreadyStartWifi = true
let res: UniWifiResult = { let res: UniWifiResult = {
errSubject: "uni-startWifi", errSubject: "uni-startWifi",
...@@ -219,7 +166,7 @@ export function startWifi(option: WifiOption) { ...@@ -219,7 +166,7 @@ export function startWifi(option: WifiOption) {
/* /*
* 停止wifi模块 * 停止wifi模块
*/ */
export function stopWifi(option: WifiOption) { export const stopWifi: StopWifi = function (option: WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = false UniWiFiModuleGloabInfo.alreadyStartWifi = false
LocationPromiseService.promiseCompletionHandler = [] LocationPromiseService.promiseCompletionHandler = []
let res: UniWifiResult = { let res: UniWifiResult = {
...@@ -235,7 +182,7 @@ export function stopWifi(option: WifiOption) { ...@@ -235,7 +182,7 @@ export function stopWifi(option: WifiOption) {
/* /*
* 获取wifi列表, 在调用之前需要引导用户跳转到系统设置-WIFI设置页面,系统搜索周边wifi后app才能接收到回调 * 获取wifi列表, 在调用之前需要引导用户跳转到系统设置-WIFI设置页面,系统搜索周边wifi后app才能接收到回调
*/ */
export function getWifiList(option: WifiOption) { export const getWifiList: GetWifiList = function (option: WifiOption) {
let res: UniWifiResult = { let res: UniWifiResult = {
errSubject: "uni-getWifiList", errSubject: "uni-getWifiList",
errCode: 12001, errCode: 12001,
...@@ -249,14 +196,14 @@ export function getWifiList(option: WifiOption) { ...@@ -249,14 +196,14 @@ export function getWifiList(option: WifiOption) {
/* 获取wifi列表的回调 /* 获取wifi列表的回调
* note: 请在getWifiList方法的回调里调用该方法 * note: 请在getWifiList方法的回调里调用该方法
*/ */
export function onGetWifiList(callback: UniWifiCallback) { export const onGetWifiList: OnGetWifiList = function (callback: UniWifiCallback) {
} }
/* /*
* 注销获取wifi列表的回调 * 注销获取wifi列表的回调
*/ */
export function offGetWifiList(callback: UniWifiCallback) { export const offGetWifiList: OffGetWifiList = function (callback: UniWifiCallback) {
} }
...@@ -264,7 +211,7 @@ export function offGetWifiList(callback: UniWifiCallback) { ...@@ -264,7 +211,7 @@ export function offGetWifiList(callback: UniWifiCallback) {
/* /*
* 获取当前连接的wifi信息 * 获取当前连接的wifi信息
*/ */
export function getConnectedWifi(option: GetConnectedWifiOptions) { export const getConnectedWifi: GetConnectedWifi = function (option: GetConnectedWifiOptions) {
if (UniWiFiModuleGloabInfo.alreadyStartWifi == false) { if (UniWiFiModuleGloabInfo.alreadyStartWifi == false) {
let res: UniWifiResult = { let res: UniWifiResult = {
errSubject: "uni-getConnectedWifi", errSubject: "uni-getConnectedWifi",
...@@ -299,7 +246,7 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) { ...@@ -299,7 +246,7 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) {
/* /*
* 连接wifi * 连接wifi
*/ */
export function connectWifi(option: WifiConnectOption) { export const connectWifi: ConnectWifi = function (option: WifiConnectOption) {
let res: UniWifiResult = { let res: UniWifiResult = {
errSubject: "uni-connectWifi", errSubject: "uni-connectWifi",
errCode: 12001, errCode: 12001,
...@@ -314,35 +261,35 @@ export function connectWifi(option: WifiConnectOption) { ...@@ -314,35 +261,35 @@ export function connectWifi(option: WifiConnectOption) {
/* /*
* 连上wifi事件的监听函数 * 连上wifi事件的监听函数
*/ */
export function onWifiConnected(callback: UniWifiCallback) { export const onWifiConnected: OnWifiConnected = function (callback: UniWifiCallback) {
} }
/* /*
* 连上wifi事件的监听函数, wifiInfo仅包含ssid * 连上wifi事件的监听函数, wifiInfo仅包含ssid
*/ */
export function onWifiConnectedWithPartialInfo(callback: UniWifiCallback) { export const onWifiConnectedWithPartialInfo: OnWifiConnectedWithPartialInfo = function (callback: UniWifiCallback) {
} }
/* /*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。 * 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/ */
export function offWifiConnected(callback: UniWifiCallback | null) { export const offWifiConnected: OffWifiConnected = function (callback: UniWifiCallback | null) {
} }
/* /*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。 * 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/ */
export function onOffWifiConnectedWithPartialInfo(callback: UniWifiCallback | null) { export const onOffWifiConnectedWithPartialInfo: OnOffWifiConnectedWithPartialInfo = function (callback: UniWifiCallback | null) {
} }
/* /*
* 设置 wifiList 中 AP 的相关信息。在 onGetWifiList 回调后调用,iOS特有接口。 * 设置 wifiList 中 AP 的相关信息。在 onGetWifiList 回调后调用,iOS特有接口。
*/ */
export function setWifiList(option: WifiOption) { export const setWifiList: SetWifiList = function (option: WifiOption) {
let res: UniWifiResult = { let res: UniWifiResult = {
errSubject: "uni-setWifiList", errSubject: "uni-setWifiList",
errCode: 12001, errCode: 12001,
......
/**
* Wifi 函数通用入参封装
*/
export type WifiOption = {
success?: (res: UniWifiResult) => void;
fail?: (res: UniWifiResult) => void;
complete?: (res: UniWifiResult) => void;
};
/**
* Wifi 链接参数封装
*/
export type WifiConnectOption = {
SSID?: string;
BSSID?: string;
password?: string;
maunal?: boolean;
partialInfo?: boolean; //ios不生效
success?: (res: UniWifiResult) => void;
fail?: (res: UniWifiResult) => void;
complete?: (res: UniWifiResult) => void;
}
/**
* 获取当前链接的wifi信息
*/
export type GetConnectedWifiOptions = {
partialInfo?: boolean
success?: (res: UniWifiResult) => void
fail?: (res: UniWifiResult) => void
complete?: (res: UniWifiResult) => void
}
/*
* 对外暴露的wifi信息
*/
export type UniWifiInfo = {
SSID: string;
BSSID?: string;
secure?: boolean;
signalStrength?: number;
frequency?: number;
}
export type UniWifiResult = {
errCode : number,
errSubject : string,
errMsg : string,
wifi: UniWifiInfo | null
}
export type UniWifiCallback = () => void
export type StartWifi = (option: WifiOption) => void
export type StopWifi = (option: WifiOption) => void
export type GetWifiList = (option: WifiOption) => void
export type OnGetWifiList = (callback: UniWifiCallback) => void
export type OffGetWifiList = (callback: UniWifiCallback) => void
export type GetConnectedWifi = (option: GetConnectedWifiOptions) => void
export type ConnectWifi = (option: WifiConnectOption) => void
export type OnWifiConnected = (callback: UniWifiCallback) => void
export type OnWifiConnectedWithPartialInfo = (callback: UniWifiCallback) => void
export type OffWifiConnected = (callback: UniWifiCallback | null) => void
export type OnOffWifiConnectedWithPartialInfo = (callback: UniWifiCallback | null) => void
export type SetWifiList = (option: WifiOption) => void
interface Uni {
startWifi : StartWifi,
stopWifi : StopWifi,
/**
* @autotest {
generated: false,
pollution: false,
cases:[
{
before: 'startWifi',
after: 'stopWifi',
input: [{
maunal:false,
SSID:"Xiaomi_20D0",
password:"streamApp!2016",
}],
output:{
callbackType: 'success',
value: { errCode: 12013 ,errMsg: "connectWifi:wifi config may be expired",errSubject: "uni-connectWifi"}
}
}
]
}
*/
connectWifi: ConnectWifi,
/**
* @autotest {
generated: false,
cases:[
{
before: 'startWifi',
after: 'stopWifi'
}
]
}
*/
getWifiList : GetWifiList,
onGetWifiList : OnGetWifiList,
offGetWifiList : OffGetWifiList,
getConnectedWifi : GetConnectedWifi,
onWifiConnected : OnWifiConnected,
onWifiConnectedWithPartialInfo : OnWifiConnectedWithPartialInfo,
offWifiConnected : OffWifiConnected,
onOffWifiConnectedWithPartialInfo : OnOffWifiConnectedWithPartialInfo,
setWifiList : SetWifiList,
}
function startWifi() {
return new Promise((resolve, reject) => {
uni.startWifi({
success: () => {
console.log('startWifi success');
resolve()
},
fail: () => {
console.log('startWifi fail');
reject()
}
})
})
}
function stopWifi() {
return new Promise((resolve, reject) => {
uni.stopWifi({
success: () => {
console.log('stopWifi success');
resolve()
},
fail: () => {
console.log('stopWifi success');
fail()
}
})
})
}
module.exports = {
startWifi,
stopWifi
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册