我正在使用 Ionic 构建一个 iOS 应用程序。现在我正在测试它在 iPad 2 中的表现,但是这样做需要我不断地写:
ionic emulate ios --target="iPad-2"
有没有办法在 ionic.project 文件中的某个地方或其他地方对此进行硬编码,以便我可以停止手动执行此操作?谢谢
最佳答案
我遇到了同样的问题,尽管这个问题已经有一年了,但这是我通过谷歌得到的第一件事,在其他任何地方都找不到答案。这就是我所做的只是因为我不想每次都使用 --target="iPhone-7"。
对于任何想要在特定 ios 设备上运行的人来说,请使用以下内容:
ionic run ios --target="iXXX-X"
iXXX-X 将是您从运行中获得的名称之一
ios-sim showdevicetypes
例如:ionic run ios --target="iPhone-7"
我想有一个解决方案使 iPhone-7 成为我的默认目标,因此运行以下命令将针对 iPhone-7(我最初的默认目标是 iPhone-SE):
ionic run ios
似乎默认值是硬编码的,因此必须在代码中进行更改。
我找到了这个文件:/platforms/ios/cordova/lib/run.js
在那里你会找到一个名为 deployToSim 的函数,我对它进行了如下更改:
function deployToSim(appPath, target) {
// Select target device for emulator. Default is 'iPhone-6'
if (!target) {
return require('./list-emulator-images').run()
.then(function(emulators) {
if (emulators.length > 0) {
target = emulators[0];
}
emulators.forEach(function(emulator) {
// this is the original condition
// if (emulator.indexOf('iPhone') === 0)
// change "iPhone" to the specific model you want, in my case it's iPhone-7
// Notice the comma in iPhone7, without comma it will take iPhone-7-plus instead
if (emulator.indexOf('iPhone-7,') === 0) {
target = emulator;
}
});
events.emit('log', 'No target specified for emulator. Deploying to ' + target + ' simulator');
return startSim(appPath, target);
});
} else {
return startSim(appPath, target);
}
}
关于ios - 如何设置默认设备以在 Ionic 中进行模拟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35296187/