安卓
1. 开启手机蓝牙(未开启会提示信息,点击去开启按钮直接跳转手机设置,开启蓝牙)
打开手机,设置——蓝牙
2. 开启手机位置信息(未开启会提示信息)
打开手机,设置——位置信息
3. 开启微信位置信息权限(未开启会提示信息,点击去开启按钮直接跳转手机微信授权管理页,开启微信位置信息权限)
打开手机,设置——应用——微信——权限——位置信息
4. 开启微信附近设备权限(暂时无法提示信息,小程序端无法判断)
打开手机,设置——应用——微信——权限——附近设备
5. 开启小程序蓝牙权限(未开启会直接跳转小程序设置页面)
IOS
1. 开启手机蓝牙(未开启会提示信息)
打开手机,设置——蓝牙
2. 开启微信蓝牙权限(未开启会提示信息,点击去开启按钮直接跳转手机微信授权管理页,开启微信位置信息权限)
打开手机,设置——微信——蓝牙
3. 开启小程序蓝牙权限(未开启会直接跳转小程序设置页面)
开启小程序位置信息权限(目前看不需要开启)
这些暂时自己遇到问题汇总,因为这个设置没有开启导致搜索不到蓝牙的问题。小程序使用者又不知道需要开启哪些设置,在程序中做了一些判断提示信息,提醒小程序使用者开启这些设置。
后面会继续补充一些代码等相关文章。
CheckSystemInfo(){
let that=this;
return new Promise((resolve, reject) => {
//获取设备设置
let systemSetting = wx.getSystemSetting();
let bluetoothEnabled = systemSetting.bluetoothEnabled;
let locationEnabled = systemSetting.locationEnabled;
//获取设备基础信息
let deviceInfo = wx.getDeviceInfo();
let platform = deviceInfo.platform;
/*
ios iOS微信(包含 iPhone、iPad)
android Android微信
windows Windows微信
mac macOS微信
devtools 微信开发者工具
*/
//获取微信APP授权设置
let appAuthorizeSetting = wx.getAppAuthorizeSetting();
let bluetoothAuthorized = appAuthorizeSetting.bluetoothAuthorized; //允许微信使用蓝牙的开关(仅 iOS 有效)
let locationAuthorized = appAuthorizeSetting.locationAuthorized;
if(!bluetoothEnabled)
{
let showCancel = false;
let confirmText = '确定';
if (platform=='android') {
showCancel = true;
confirmText = '去开启';
}
wx.showModal({
content: '请进入手机设置开启蓝牙',
showCancel:showCancel,
confirmText:confirmText,
success: function (res) {
if (res.confirm) {
console.log('用户点击确定')
if (platform=='android') {
wx.openSystemBluetoothSetting({
success (res) {
console.log(res)
}
})
}
} else if (res.cancel) {
console.log('用户点击取消')
}
}
});
resolve(false);
}
else
{
//小程序的蓝牙权限
wx.getSetting({
success: (res) => {
//console.log(res, res.authSetting[scopeName],!res.authSetting[scopeName], scopeName)
//小程序 ** 权限
if (!res.authSetting['scope.bluetooth']) {
// 没有权限
wx.showModal({
title: '提示',
content: '请开启小程序蓝牙权限',
showCancel: false,
success: modalSuccess => {
wx.openSetting();
}
});
resolve(false);
}
else
{
if (platform=='android') {
if (!locationEnabled) {
wx.showModal({
content: '请进入手机设置开启位置信息',
showCancel:false,
success: function (res) {
console.log(res);
}
});
resolve(false);
}
else
{
if (locationAuthorized!=='authorized') {
wx.showModal({
content: '请进入手机设置开启微信应用的位置信息权限',
showCancel:true,
confirmText:'去开启',
success: function (res) {
console.log(res);
if (res.confirm) {
console.log('用户点击确定')
wx.openAppAuthorizeSetting({
success (res) {
console.log('系统微信授权管理页', res)
}
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
});
resolve(false);
}
else
{
resolve(true);
}
}
}
else if (platform=='ios')
{
if (bluetoothAuthorized!=='authorized') {
wx.showModal({
content: '请进入手机设置开启微信应用的蓝牙权限',
showCancel:true,
confirmText:'去开启',
success: function (res) {
console.log(res);
if (res.confirm) {
console.log('用户点击确定')
wx.openAppAuthorizeSetting({
success (res) {
console.log('系统微信授权管理页', res)
}
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
});
resolve(false);
}
else
{
resolve(true);
}
}
else
{
resolve(true);
}
}
},
fail: (err) => {
reject(err)
}
})
}
});
}