const requestLocationAuth = async () => {
try {
const settings = await getSetting();
const hasAuth = settings.authSetting['scope.userLocation'];
if (hasAuth) {
await getLocationFn();
} else {
const res = await authorize({
scope: 'scope.userLocation'
});
if (res.errMsg === 'authorize:ok') {
await getLocationFn();
}
}
} catch (error) {
showModal({
title: '授权失败',
content: '请在设置中授权获取地理位置权限',
showCancel: false,
success: () => openSetting()
});
}
};
上述getLocationFn方法为封装的getLocation方法。IOS中,authorize弹窗前,返回上一个页面再进入,弹窗隐私点同意,后续返回都会连续返回两次