wifiInfomation.vue 1.0 KB
Newer Older
lizhongyi_'s avatar
lizhongyi_ 已提交
1
<template>
lizhongyi_'s avatar
lizhongyi_ 已提交
2
	<page-head :title="获取当前连接wifi信息" accordion></page-head>
lizhongyi_'s avatar
lizhongyi_ 已提交
3 4 5 6 7 8 9
	<view class="uni-padding-wrap uni-common-mt">
		<button @tap="getLocationPromise">获取定位权限</button>
		<button @tap="getWifiInfo">获取WiFi信息</button>
	</view>
</template>

<script>
lizhongyi_'s avatar
lizhongyi_ 已提交
10

11
	import { getCurrentWifiInfo, requestLocationPromise } from '@/uni_modules/uni-wifiinformation';
lizhongyi_'s avatar
lizhongyi_ 已提交
12 13

	export default {
lizhongyi_'s avatar
lizhongyi_ 已提交
14
		 
lizhongyi_'s avatar
lizhongyi_ 已提交
15 16
		methods:{
			getLocationPromise() {
17 18 19 20 21 22 23
				requestLocationPromise(function(res){
						console.log(res)
						uni.showToast({
							title: res["message"],
							icon: 'none'
						})
				})
lizhongyi_'s avatar
lizhongyi_ 已提交
24 25 26 27
			},
			
			getWifiInfo() {
				/* iOS12之后获取wifi信息需要获取系统定位权限,否则获取到的wifi信息为空 */
28 29 30 31 32 33 34 35 36 37 38 39
				requestLocationPromise(function(res) {
					if (res["success"] == true) {
						let wifiInfo = getCurrentWifiInfo()
						if (wifiInfo != null) {
							console.log(wifiInfo)
							uni.showToast({
								title: "当前wifi信息获取成功",
								icon: 'none'
							})
						}
					}
				})
lizhongyi_'s avatar
lizhongyi_ 已提交
40
			},
lizhongyi_'s avatar
lizhongyi_ 已提交
41 42 43 44 45 46 47
			
		}
	}
</script>

<style>
</style>