我使用了创建了一个cordova项目cordova create project hello com.hello Hello
.
并添加了iOS平台使用cordova platform add iOS
.并试图做cordova run ios
以后cordova build ios
.
但它告诉我这个错误(我用--d/--verbose来获取细节).
/ usr/bin/codesign --force --sign - --timestamp = none /Volumes/Untitled/Plot/PlotReel/platforms/ios/build/emulator/PlotReel.app/Volumes/Untitled/Plot/PlotReel/platforms/ios /build/emulator/PlotReel.app:替换现有签名
**建立成功**
找不到钩子"before_deploy"的脚本.错误:TypeError:无法读取undefined的属性'replace'
at remove (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/ios-sim/src/lib.js:282:70)
at Array.forEach (native)
at Object.getdevicetypes (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/ios-sim/src/lib.js:292:22)
at Object.listEmulatorImages [as run] (/Volumes/Untitled/Plot/test/platforms/ios/cordova/lib/list-emulator-images:34:29)
at deployToSim (/Volumes/Untitled/Plot/test/platforms/ios/cordova/lib/run.js:146:50)
at /Volumes/Untitled/Plot/test/platforms/ios/cordova/lib/run.js:88:20
at _fulfilled (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/q/q.js:863:30)
at Promise.promise.promiseDispatch (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/q/q.js:796:13)
at /Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/q/q.js:604:44
我已经尝试再次卸载并安装cordova,但问题仍然存在.
请帮我.
1> Tadej..:
新解决方案
这个问题在最新版本的"ios-sim"软件包中得到修复(所以现在这可能是更简单的解决方案 - 与下面列出的旧版本相比).为了将"ios-sim"软件包更新到最新版本,请在终端/ cmd中运行:
cd platforms/ios/cordova/node_modules/
sudo npm install -g ios-sim@latest
老解决方案
问题是" iPad Pro(12.9英寸) "和" iPad Pro(10.5英寸) " 的name_id_map[deviceName]
回报.undefined
你可以用它来检查console.log('name_id_map[ deviceName ]: ' + name_id_map[ deviceName ]);
.
我通过添加if语句来修复此错误,该语句检查设备是否在" platforms/ios/cordova/node_modules/ios-sim/src/lib.js:282 "中定义.
我替换了这个:
list = [];
var remove = function(runtime) {
// remove "iOS" prefix in runtime, remove prefix "com.apple.CoreSimulator.SimDeviceType." in id
list.push(util.format('%s, %s', name_id_map[ deviceName ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, '')));
};
有了这个:
list = [];
var remove = function(runtime) {
// remove "iOS" prefix in runtime, remove prefix "com.apple.CoreSimulator.SimDeviceType." in id
if (name_id_map[deviceName] && runtime) {
list.push(util.format('%s, %s', name_id_map[deviceName].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, '')));
}
};
"iPad Pro(10.5英寸)"模拟器不在列表中(但它无论如何都不会起作用 - 没有检查).
关于github的错误报告:https://github.com/phonegap/ios-sim/issues/210
我可以确认,以下对我有用:$ cd platforms/ios/cordova/node_modules/$ sudo npm install ios-sim @ latest
2> Reza..:
在你的项目文件夹root中,做 cd platforms/ios/cordova && npm install ios-sim
3> 小智..:
我有同样的错误.对我来说,我追溯到平台/ ios/cordova/node_modules/ios-sim/src/lib.js中的一个错误
getdevicetypes: function(args) {
...
list.devicetypes.forEach(function(device) {
name_id_map[ filterDeviceName(device.name) ] = device.id;
});
list = [];
var remove = function(runtime) {
// remove "iOS" prefix in runtime, remove prefix "com.apple.CoreSimulator.SimDeviceType." in id
list.push(util.format('%s, %s', name_id_map[ deviceName ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, '')));
};
错误总是在lib.js:289中出现"TypeError:无法读取属性'替换'未定义"
list.push(util.format('%s, %s', name_id_map[ deviceName ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, '')));
所以我插入了一些调试代码:
list.devicetypes.forEach(function(device) {
console.log('test 1 ' + device.name);
console.log('test 2 ' + filterDeviceName(device.name));
name_id_map[ filterDeviceName(device.name) ] = device.id;
});
这对我有用.祝好运.
list = [];
var remove = function(runtime) {
// remove "iOS" prefix in runtime, remove prefix "com.apple.CoreSimulator.SimDeviceType." in id
console.log('remove 1 ' + runtime);
console.log('remove 2 ' + deviceName);
console.log('remove 3 ' + name_id_map[ deviceName ]);
list.push(util.format('%s, %s', name_id_map[ deviceName ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, '')));
};
得到以下输出:
test 1 iPhone 5
test 2 iPhone 5
test 1 iPad Pro (9.7-inch)
test 2 iPad Pro (9.7 inch)
remove 1 iOS 10.2
remove 2 iPhone 5
remove 3 com.apple.CoreSimulator.SimDeviceType.iPhone-5
remove 1 iOS 10.2
remove 2 iPad Pro (9.7-inch)
remove 3 undefined
请注意filterDeviceName如何在填充哈希时删除减号.再次检索值时,不应用过滤器并且程序失败.
错误修复:在写入和读取哈希时应用过滤器.
list.push(util.format('%s, %s', name_id_map[ filterDeviceName(deviceName) ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, '')));
非常感谢我的朋友,它很有效.您是否发送了针对该错误修复的拉取请求?
4> Hirbod..:
Github上有一个公关解决了我的问题:https:
//github.com/phonegap/ios-sim/pull/213
刚刚调用我的项目根目录
nano platforms/ios/cordova/node_modules/ios-sim/src/lib.js
并添加了过滤设备名称的功能,如下所示:https:
//github.com/phonegap/ios-sim/pull/213/files