uni-app 3.4.6版本无法获取ios底部安全区距离

uni-app 3.4.6版本无法获取ios底部安全区距离

开发环境 版本号 项目创建方式
Windows 10 HBuilderX

产品分类:uniapp/App
PC开发环境操作系统:Windows
PC开发环境操作系统版本号:windows 10
HBuilderX类型:正式
HBuilderX版本号:3.4.6
手机系统:iOS
手机系统版本号:iOS 15
手机厂商:苹果
手机机型:iphone 13
页面类型:nvue
vue版本:vue2
打包方式:云端
项目创建方式:HBuilderX

示例代码:

uni.getSystemInfo({
    success: (res) => {  
        console.log(res)  
        this.safeBottom = res.safeAreaInsets.bottom + 'px'  
    }  
})
{
    "errMsg": "getSystemInfo:ok",  
    "brand": "Apple",  
    "model": "iPhone13",  
    "pixelRatio": 3,  
    "screenWidth": 390,  
    "screenHeight": 844,  
    "windowWidth": 390,  
    "windowHeight": 810,  
    "statusBarHeight": 47,  
    "language": "zh-Hans-CN",  
    "system": "iOS 15.4.1",  
    "version": "1.9.9.80820",  
    "fontSizeSetting": "",  
    "platform": "ios",  
    "SDKVersion": "",  
    "windowTop": 0,  
    "windowBottom": 0,  
    "safeArea": {  
        "left": 0,  
        "right": 390,  
        "top": 47,  
        "bottom": 810,  
        "width": 390,  
        "height": 763  
    },  
    "safeAreaInsets": {  
        "top": 47,  
        "right": 0,  
        "bottom": 0,  
        "left": 0  
    }  
}

操作步骤:

uni.getSystemInfo({
    success: (res) => {
        console.log(res)
        this.safeBottom = res.safeAreaInsets.bottom + 'px'
    }
})

预期结果:

获取到安全区距离

实际结果:

安全区距离为0


更多关于uni-app 3.4.6版本无法获取ios底部安全区距离的实战教程也可以访问 https://www.itying.com/category-93-b0.html

10 回复

同样遇到了该问题,只能切换回上一个版本

更多关于uni-app 3.4.6版本无法获取ios底部安全区距离的实战教程也可以访问 https://www.itying.com/category-93-b0.html


云打包还是一样的问题,云打包强制用最新的,哎

问题确认,已加分,后续修复

HX 3.4.7 已修复

已经更新到HX 3.4.7 了 ipone 系列 在nvue下获取的safeAreaInsets.bottom 还是0

3.4.7 真机ios还是有问题
plus.navigator.getSafeAreaInsets 在安卓下 top 会取到0,所以只能2个一起结合使用
function getInsets() {
const { top, bottom } = uni.getSystemInfoSync().safeAreaInsets
const value = { top, bottom }
if (!bottom) {
// 规避 苹果,uni.getSystemInfoSync().safeAreaInsets.bottom 可能为0
// 相关问题:https://ask.dcloud.net.cn/question/143633
value.bottom = plus.navigator.getSafeAreaInsets().bottom
}
return value
}

3.4.15也是,ios真机下无法获取

uni-app 3.4.6 版本中,如果你无法获取 iOS 设备的底部安全区距离,可能是因为没有正确使用 uni.getSystemInfoSync()uni.getSystemInfo() 方法来获取设备信息。iOS 设备的底部安全区距离通常可以通过 safeAreaInsets 属性来获取。

以下是一个示例代码,展示如何获取 iOS 设备的底部安全区距离:

// 获取系统信息
const systemInfo = uni.getSystemInfoSync();

// 检查是否存在 safeAreaInsets
if (systemInfo.safeAreaInsets) {
    const bottomSafeArea = systemInfo.safeAreaInsets.bottom;
    console.log('底部安全区距离:', bottomSafeArea);
} else {
    console.log('无法获取底部安全区距离');
}

注意事项:

  1. iOS 设备safeAreaInsets 属性仅在 iOS 设备上有效,Android 设备上可能不存在该属性。
  2. 版本兼容性:确保你使用的 uni-app 版本支持 safeAreaInsets 属性。如果你使用的是较旧的版本,可能需要升级到最新版本。
  3. 真机调试:在模拟器上可能无法正确获取安全区距离,建议在真机上进行调试。

其他方法:

如果你仍然无法获取底部安全区距离,可以尝试使用 uni.getWindowInfo() 方法来获取窗口信息,其中也包含了安全区的信息。

const windowInfo = uni.getWindowInfo();

if (windowInfo.safeAreaInsets) {
    const bottomSafeArea = windowInfo.safeAreaInsets.bottom;
    console.log('底部安全区距离:', bottomSafeArea);
} else {
    console.log('无法获取底部安全区距离');
}
回到顶部