uni-app iOS 启动白屏问题

发布于 1周前 作者 itying888 来自 Uni-App

uni-app iOS 启动白屏问题

产品分类:  
uni小程序SDK  

手机系统:  
iOS  

手机系统版本号:  
iOS 13.2  

手机厂商:  
苹果  

手机机型:  
iphone7  

页面类型:  
vue  

SDK版本号:  
4.0.8  

### 操作步骤:

# CoreApp##...app start load..

2024-09-02 10:43:55.929131+0800 smarthome[1021:31890] [Runtime][DEBUG:] ##CoreApp##...createAppRuntime..
2024-09-02 10:43:55.950847+0800 smarthome[1021:31890] [Runtime][DEBUG:] ##CoreApp##...createAppWindow..
2024-09-02 10:43:55.957954+0800 smarthome[1021:31890] [Runtime][DEBUG:] ##CoreApp##...创建首页..
2024-09-02 10:43:55.968789+0800 smarthome[1021:32095] <Weex>[error]script_bridge.h:168, <WeexCore> xxx set_core_side is runing and 0x283ff9d60
2024-09-02 10:43:56.026603+0800 smarthome[1021:32093] <Weex>[error]WXMonitor.m:289, [WX_KEY_EXCEPTION_WXBRIDGE] [undefined:undefined:undefined] TypeError: undefined is not an object js stack: (null)
2024-09-02 10:43:56.037587+0800 smarthome[1021:31890] [Runtime][INFO:] refreshWhitePageCheckWebview---evt[3]---[<PDRCoreAppFrame: 0x105173a00; frame = (0 0; 375 667); clipsToBounds = YES; layer = <CALayer: 0x283d68100>>]

预期结果:

CoreApp##…app start load…

2024-09-02 10:43:55.929131+0800 smarthome[1021:31890] [Runtime][DEBUG:] ##CoreApp##…createAppRuntime… 2024-09-02 10:43:55.950847+0800 smarthome[1021:31890] [Runtime][DEBUG:] ##CoreApp##…createAppWindow… 2024-09-02 10:43:55.957954+0800 smarthome[1021:31890] [Runtime][DEBUG:] ##CoreApp##…创建首页… 2024-09-02 10:43:55.968789+0800 smarthome[1021:32095] <Weex>[error]script_bridge.h:168, <WeexCore> xxx set_core_side is runing and 0x283ff9d60 2024-09-02 10:43:56.026603+0800 smarthome[1021:32093] <Weex>[error]WXMonitor.m:289, [WX_KEY_EXCEPTION_WXBRIDGE] [undefined:undefined:undefined] TypeError: undefined is not an object js stack: (null) 2024-09-02 10:43:56.037587+0800 smarthome[1021:31890] [Runtime][INFO:] refreshWhitePageCheckWebview—evt[3]—[<PDRCoreAppFrame: 0x105173a00; frame = (0 0; 375 667); clipsToBounds = YES; layer = <CALayer: 0x283d68100>>]


### 实际结果:

# CoreApp##...app start load..

2024-09-02 10:43:55.929131+0800 smarthome[1021:31890] [Runtime][DEBUG:] ##CoreApp##...createAppRuntime..
2024-09-02 10:43:55.950847+0800 smarthome[1021:31890] [Runtime][DEBUG:] ##CoreApp##...createAppWindow..
2024-09-02 10:43:55.957954+0800 smarthome[1021:31890] [Runtime][DEBUG:] ##CoreApp##...创建首页..
2024-09-02 10:43:55.968789+0800 smarthome[1021:32095] <Weex>[error]script_bridge.h:168, <WeexCore> xxx set_core_side is runing and 0x283ff9d60
2024-09-02 10:43:56.026603+0800 smarthome[1021:32093] <Weex>[error]WXMonitor.m:289, [WX_KEY_EXCEPTION_WXBRIDGE] [undefined:undefined:undefined] TypeError: undefined is not an object js stack: (null)
2024-09-02 10:43:56.037587+0800 smarthome[1021:31890] [Runtime][INFO:] refreshWhitePageCheckWebview---evt[3]---[<PDRCoreAppFrame: 0x105173a00; frame = (0 0; 375 667); clipsToBounds = YES; layer = <CALayer: 0x283d68100>>]

bug描述:

CoreApp##…app start load…

2024-09-02 10:43:55.929131+0800 smarthome[1021:31890] [Runtime][DEBUG:] ##CoreApp##…createAppRuntime… 2024-09-02 10:43:55.950847+0800 smarthome[1021:31890] [Runtime][DEBUG:] ##CoreApp##…createAppWindow… 2024-09-02 10:43:55.957954+0800 smarthome[1021:31890] [Runtime][DEBUG:] ##CoreApp##…创建首页… 2024-09-02 10:43:55.968789+0800 smarthome[1021:32095] <Weex>[error]script_bridge.h:168, <WeexCore> xxx set_core_side is runing and 0x283ff9d60 2024-09-02 10:43:56.026603+0800 smarthome[1021:32093] <Weex>[error]WXMonitor.m:289, [WX_KEY_EXCEPTION_WXBRIDGE] [undefined:undefined:undefined] TypeError: undefined is not an object js stack: (null) 2024-09-02 10:43:56.037587+0800 smarthome[1021:31890] [Runtime][INFO:] refreshWhitePageCheckWebview—evt[3]—[<PDRCoreAppFrame: 0x105173a00; frame = (0 0; 375 667); clipsToBounds = YES; layer = <CALayer: 0x283d68100>>]


2 回复

看报错是 js 语法报错了,先真机运行一下看看是否能在基座中正常运行


针对uni-app在iOS设备上启动时出现的白屏问题,这通常与应用的资源加载、页面渲染或配置错误有关。以下是一些可能的原因及相应的代码或配置检查示例,帮助你定位和解决问题。

1. 检查manifest.json配置

确保manifest.json中的app-plus配置正确,特别是与iOS相关的配置,如app-idversion等。

"app-plus": {
    "name": "yourAppName",
    "version": {
        "name": "1.0.0",
        "code": "100"
    },
    "distribute": {
        "apple": {
            "appid": "your-apple-app-id",
            "teamId": "your-team-id"
        }
    },
    // 其他配置...
}

2. 优化首页加载逻辑

白屏可能是首页数据加载时间过长导致的。优化首页的数据请求和渲染逻辑,确保页面尽快显示。

// 在页面onLoad或mounted生命周期中异步加载数据
onLoad() {
    uni.showLoading({ title: '加载中...' });
    setTimeout(() => {
        // 模拟数据加载
        this.setData({
            dataLoaded: true,
            list: [...] // 数据列表
        });
        uni.hideLoading();
    }, 1000); // 假设数据加载需要1秒
}

3. 检查资源文件路径

确保所有引用的资源文件路径正确,特别是图片、CSS和JS文件。错误的路径会导致资源加载失败,从而引起白屏。

<!-- 在页面中使用相对路径引用资源 -->
<image src="../../static/logo.png" mode="aspectFit"></image>
<link rel="stylesheet" href="../../static/styles.css">
<script src="../../static/script.js"></script>

4. 使用条件编译区分平台代码

有时候,iOS和Android平台需要不同的代码实现。使用条件编译来区分平台代码。

// #ifdef APP-PLUS-IOS
console.log('This is iOS specific code');
// #endif

// #ifdef APP-PLUS-ANDROID
console.log('This is Android specific code');
// #endif

5. 清理和重建项目

最后,尝试清理项目并重新构建,以确保所有最新的更改都被正确编译和应用。

# 清理和重建uni-app项目
npm run clean
npm run build

通过上述步骤,你应该能够定位并解决uni-app在iOS设备上启动时出现的白屏问题。如果问题依旧存在,建议检查uni-app的官方文档和社区,看看是否有其他开发者遇到并解决了类似的问题。

回到顶部