import permision from "@/js_sdk/wa-permission/permission.js"
async function requestAndroidPermission(permisionID = 'android.permission.ACCESS_FINE_LOCATION', getLoacNum=1) {
/*
permisionID : 需要操作的id默认为定位权限
restartAppType : 重启APP的缓存,跳转页面用的
*/
let routes = getCurrentPages();
let restartAppType = routes[routes.length - 1].route; //页面名字
// #ifdef APP-PLUS
let result;
if (plus.os.name == "iOS") {
result = await permision.judgeIosPermissionLocation()
} else {
result = await permision.requestAndroidPermission(permisionID)
}
// #endif
return new Promise((resolve, reject) => {
// #ifdef APP-PLUS
uni.getLocation({
type: 'wgs84',
success: function(res) {
console.log('进来获取经纬度了', getLoacNum)
resolve(res)
},
fail: function() {
//打开授权设置
console.log('地址错误了 ', getLoacNum)
getLoacNum += 1
if(getLoacNum<6){
requestAndroidPermission(permisionID = 'android.permission.ACCESS_FINE_LOCATION', getLoacNum)
}else{
if (result == 1) { //已获取到位置权限,但是需要重新启动APP
uni.showModal({ //重启APP
title: "温馨提示",
content: "请点击确定按钮重启APP",
showCancel: false,
success(res) {
if (res.confirm) {
uni.setStorageSync('restartApp', restartAppType)
plus.runtime.restart(); //重启APP
}
}
})
reject(result)
} else {
uni.showModal({
title: '温馨提示',
content: '您已拒绝定位,请开启',
confirmText: '去设置',
success(res) {
if (res.confirm) { //去设置权限问题
permision.gotoAppPermissionSetting(permisionID)
// that.openSetting()
} else {
console.log('点击拒绝按钮了', res)
resolve(1)
}
}
})
}
}
}
});
// #endif
// #ifdef H5
// 默认给广州
resolve({
"type": "WGS84",
"altitude": 0,
latitude: 23.101308, //广州坐标
longitude: 113.361075,
"speed": 0,
"accuracy": 30,
"errMsg": "getLocation:ok"
})
// #endif
}).catch((e) => {
return e
})
}
3***@qq.com
- 发布:2021-09-12 11:26
- 更新:2021-10-14 14:09
- 阅读:651
1 个回复
7***@qq.com
同问,大佬您的问题解决了吗