uni-app 离线打包在IOS13和14上,使用video、live-pusher组件开发的nvue页面进入时APP卡死、闪退

uni-app 离线打包在IOS13和14上,使用video、live-pusher组件开发的nvue页面进入时APP卡死、闪退

项目信息 详细信息
PC开发环境 Mac
PC开发环境版本号 10.15.6
HBuilderX类型 正式
HBuilderX版本号 2.3.3
手机系统 iOS
手机系统版本号 IOS 14
手机厂商 苹果
手机机型 iPhone XR
页面类型 nvue
打包方式 离线
项目创建方式 HBuilderX

操作步骤:

  • 进入直播页面

预期结果:

  • 点击进入直播页面后正常直播或观看

实际结果:

  • 点击进入直播页面后无响应,APP无反应,点击其他菜单也不能跳转,或直接闪退

bug描述:

该页面为直播功能,使用video、live-pusher组件开发的nvue页面。 使用HBuilderX生成的本地打包APP资源,xcode12.4打包的APP,在IOS13和14上进入直播页面时APP卡死、闪退。

直播页面直播组件使用:

<!-- 主播推流 -->  
<live-pusher id='livePusher' ref="livePusher" class="live_pusher" :url="liveData.liveSrc" :mode="mode" :muted="muted"  
:enable-camera="enableCamera" :auto-focus="autoFocus" :beauty="beauty" :whiteness="whiteness" :aspect="aspect"  
[@statechange](/user/statechange)="statechange" [@netstatus](/user/netstatus)="netstatus" [@error](/user/error)="error" v-if="isAnchor" />  
<!-- 观众拉流 -->  
<video id="myVideo" v-else controls="false" :src="liveData.liveRtmp" :muted="muted" [@error](/user/error)="error" [@ended](/user/ended)="ended"  
autoplay :style="{height: height,width: width}" />

运行报错内容:
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'threading violation: expected the main thread'
terminating with uncaught exception of type NSException  

网上查询出现的原因及解决方案:在iOS13中,系统对在子线程进行UI操作做了更加严格的检验,如果我们在子线程中更新UI,则会直接因为线程违规而导致Crash。
通过查看自己涉及到线程的代码,确认是否在非主线程中加了更新UI的操作。通常在堆栈信息中我们可以查看到具体出错的函数,找到问题后,只需把更新UI的操作放在主线程中实现即可。

更多关于uni-app 离线打包在IOS13和14上,使用video、live-pusher组件开发的nvue页面进入时APP卡死、闪退的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

HX运行项目有问题吗? 我们的离线demo运行有问题吗?

更多关于uni-app 离线打包在IOS13和14上,使用video、live-pusher组件开发的nvue页面进入时APP卡死、闪退的实战教程也可以访问 https://www.itying.com/category-93-b0.html


HX调试运行没问题,Xcode调试运行也没问题。 但是Archive打包后,安装到IOS手机闪退,目前还有找原因,不知道有没有知道的大佬告诉一下。

这是一个典型的iOS主线程UI操作问题。在iOS13及以上版本,苹果加强了对UI线程的校验机制。

问题分析:

  1. 报错信息显示"threading violation: expected the main thread",说明video或live-pusher组件在非主线程进行了UI操作
  2. 在iOS13+系统中,非主线程更新UI会直接导致崩溃

解决方案:

  1. 确保所有UI操作都在主线程执行。对于video和live-pusher组件:
// 修改组件回调方法
statechange(e) {
    dispatch_async(dispatch_get_main_queue(), ^{
        // 在这里处理UI更新
    });
}
  1. 检查原生插件代码:
  • 确保所有涉及UI的原生代码都使用主线程
  • 特别是初始化video/live-pusher组件的代码
  1. 升级HBuilderX到最新版本:
  • 2.3.3版本较旧,可能存在已知的线程问题
  • 最新版本已针对iOS13+做了适配优化
  1. 检查manifest.json配置:
{
    "ios": {
        "UIRequiresFullScreen": true,
        "EnableFrameDebug": false
    }
}
回到顶部