uni-app mui程序打包后报错 TypeError: undefined is not an object (evaluating plus.webview.currentWebview())
uni-app mui程序打包后报错 TypeError: undefined is not an object (evaluating plus.webview.currentWebview())
示例代码:
data: {
id: plus.webview.currentWebview().item.id,
}
操作步骤:
data: {
id: plus.webview.currentWebview().item.id, 这个代码报错
}
预期结果:
正常获取参数
实际结果:
获取不到
bug描述:
3月的时候更新程序打包还正常的,今天证书到期 更换了苹果证书 我是企业版的证书,程序没有任何修改再次打包后打开程序,首页功能等都正常,但是在内容列表页面,打开详情页面的时候就报错了,看着好像是获取不到列表页面传过来的参数。ios系统出问题安卓正常,ios选择的是 UIWebview
更多关于uni-app mui程序打包后报错 TypeError: undefined is not an object (evaluating plus.webview.currentWebview())的实战教程也可以访问 https://www.itying.com/category-93-b0.html
mui项目已停止维护,如果功能没有改动,只是修改证书,建议使用三方工具重签ipa即可。
可以使用爱思助手,“工具箱” -> “IPA签名”
更多关于uni-app mui程序打包后报错 TypeError: undefined is not an object (evaluating plus.webview.currentWebview())的实战教程也可以访问 https://www.itying.com/category-93-b0.html
大哥非常感谢您回复我的问题,我这边是一个公司内部用的项目,很老很复杂一直有功能更新的,是不是你们打包机的xcode更新版本了呀?有什么办法能解决吗?我看 开发者后台有个付费独享打包机,能否使用包版本的打包机?
回复 飞机头: 云端XCode打包环境从4月份已更新XCode15.2,从你提供的信息看应该很可能是这个原因导致。 建议升级项目类型到uni-app适配,uiwebview已经被苹果废弃,后续新版本ios可能会不再支持,存在风险。 如果需要定制付费独享打包机,请发邮件联系 bd@dcloud.io 。
回复 DCloud_App_Array: 好的 谢谢 我已经在开发者后台 独享打包机 这里充值了,也不知道怎么使用,我发送邮件 bd@dcloud.io 到这个邮箱 说明情况是吧?这次先处理掉,后续 跟领导申请 是需要升级了
在 uni-app 开发过程中,如果你在打包后遇到 TypeError: undefined is not an object (evaluating 'plus.webview.currentWebview()')
错误,通常是因为你在代码中使用了 plus.webview.currentWebview()
,但这个 API 在 H5 或小程序环境中并不存在。plus
对象是 HTML5+ (H5+) 的原生扩展 API,主要用于原生 App 环境(如 Android 和 iOS),在 H5 或小程序环境中不可用。
解决方案
1. 环境判断
在调用 plus.webview.currentWebview()
之前,先判断当前运行环境是否为原生 App 环境。可以使用 uni.getSystemInfoSync()
或 uni.getEnv()
来判断环境。
// 判断当前运行环境
if (uni.getSystemInfoSync().platform === 'android' || uni.getSystemInfoSync().platform === 'ios') {
// 原生 App 环境
const currentWebview = plus.webview.currentWebview();
// 其他操作
} else {
// H5 或小程序环境
console.log('当前环境不支持 plus.webview.currentWebview()');
}
或者使用 uni.getEnv()
:
if (uni.getEnv() === 'APP-PLUS') {
// 原生 App 环境
const currentWebview = plus.webview.currentWebview();
// 其他操作
} else {
// H5 或小程序环境
console.log('当前环境不支持 plus.webview.currentWebview()');
}
2. 使用 uni-app
提供的 API
uni-app
提供了跨平台的 API,尽量使用这些 API 来代替原生 API。例如,如果你需要获取当前页面的实例,可以使用 uni.getCurrentPages()
。
const pages = uni.getCurrentPages();
const currentPage = pages[pages.length - 1];
console.log(currentPage);
3. 避免在 H5 或小程序中使用原生 API
如果你需要在 H5 或小程序环境中运行,尽量避免使用 plus
相关的原生 API。可以通过条件编译或环境判断来区分不同环境的代码。
// #ifdef APP-PLUS
const currentWebview = plus.webview.currentWebview();
// #endif
// #ifdef H5
console.log('当前环境是 H5');
// #endif
// #ifdef MP-WEIXIN
console.log('当前环境是微信小程序');
// #endif