uni-app 在iOS15.0.2 版本中位置授权点击不允许导致应用崩溃
uni-app 在iOS15.0.2 版本中位置授权点击不允许导致应用崩溃
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| Windows | 企业版 LTSC | HBuilderX |
操作步骤:
- iPad 应用上
- 启动该应用程序
- 点击一个 button
- 在位置用途点击“不允许”
- 崩溃
测试插件:https://ext.dcloud.net.cn/plugin?id=5605
test(){
let location = await gps.getLocation()
if (location) {
this.login()
}else{
this.login()
}
}
预期结果:
- 正常运行
实际结果:
"threads" : [
{
"triggered":true,
"id":1985937,
"threadState":{
"x":[
{"value":10792691648},
{"value":4344680998},
{"value":0},
...
],
...
},
...
},
...
]
更多关于uni-app 在iOS15.0.2 版本中位置授权点击不允许导致应用崩溃的实战教程也可以访问 https://www.itying.com/category-93-b0.html
7 回复
复现的代码发一下
更多关于uni-app 在iOS15.0.2 版本中位置授权点击不允许导致应用崩溃的实战教程也可以访问 https://www.itying.com/category-93-b0.html
已修改,请查看
回复 小小白啊: 你这个是插件的问题吧,联系下插件作者看看
回复 小小白啊: 用uni的api都是没问题的
感谢回复,确实是插件问题。
这是一个典型的iOS 15系统权限回调处理异常导致的崩溃问题。在iOS 15中,苹果对位置权限的授权流程做了调整,当用户点击"不允许"时,系统回调的处理方式与之前版本有所不同。
从你的代码来看,主要问题在于:
- 缺少权限状态检查:在调用
getLocation()之前,应该先检查位置权限状态 - 异常处理不完善:当用户拒绝授权时,
getLocation()可能返回异常,但你的代码没有正确处理这种情况
建议修改代码如下:
async test() {
try {
// 先检查权限状态
const status = await gps.checkPermission()
if (status === 'authorized') {
let location = await gps.getLocation()
if (location) {
this.login()
}
} else if (status === 'denied') {
// 用户已拒绝,提示用户去设置中开启
uni.showModal({
title: '提示',
content: '需要位置权限才能使用此功能,请前往设置开启',
showCancel: false
})
} else {
// 未请求过权限,先请求权限
const result = await gps.requestPermission()
if (result === 'authorized') {
let location = await gps.getLocation()
if (location) {
this.login()
}
}
}
} catch (error) {
console.error('位置获取失败:', error)
// 即使获取位置失败,也应该允许登录
this.login()
}
}


