最近跟新了xcode后,发现使用cordova项目打包app是出现了下面错误
Cannot read property ‘toLowerCase’ of undefined
在网上找了许久才找到解决方案,结果!!! 有出现了Cannot read property ''name" of undefined 的报错,你他…,调试和查找许久,终于找到了问题所在和解决方案,现在记下来做个记录
1. Cannot read property ‘toLowerCase’ of undefined
报错位置://platforms/ios/cordova/lib/list-emulator-build-targets 第54行的device.availability.toLowerCase()
修改:
将
if (device.name === deviceType.name.replace(/\-inch/g, ' inch') &&
device.availability.toLowerCase().indexOf('unavailable') < 0) {
availAcc.push(device);
}
改为:
if (device.name === deviceType.name || device.name === deviceType.name.replace(/\-inch/g, ' inch')) {
// Check new flag isAvailable (XCode 10.1+) or legacy string availability (XCode 10 and lower)
if (device.isAvailable || (device.availability && device.availability.toLowerCase().indexOf('unavailable') < 0)) {
availAcc.push(device);
}
}
参考自https://www.cnblogs.com/oliverreal/p/9859343.html
2. Cannot read property ''name" of undefined
如果你是按照上面的参考链接中的方法来修改就会设置再打包的时候就会出现这个错误
报错位置:/platforms/ios/cordova/lib/build.js 的第68行,如下图:
原因:在/platforms/ios/cordova/lib/list-emulator-build-targets文件中的第55行中的device.isAvailable 的值不再是 YES
和 NO
了,而变成了true
和false
,使用在build.js 中拿不到数据
修改:将device.isAvailable == "YES"
改为 device.isAvailable
或加上 || device.isAvailable === true