我正在使用Cordova开发一个跨平台的移动应用程序,主要关注开发阶段的iOS.
对于我的开发过程,如果我可以直接从命令行启动我的Cordova应用程序并将其加载到指定的模拟器中,那将是理想的选择.我可以通过从项目根目录运行以下命令来完成此操作:
$cordova run --debug --emulator iOS
这很好用,导致iOS模拟器在带有iOS 7.0.3的模拟iPhone 4 Retina中运行我的应用程序
除了这个模拟设备,我还想测试(例如)iPad.我安装了这些仿真图像,我可以在Xcode中手动启动我的应用程序.此外,命令list-emulator-images
(位于project_dir/platforms/ios/cordova/lib
)提供以下输出:
"iPhone Retina (3.5-inch)" "iPhone Retina (4-inch)" "iPhone Retina (4-inch 64-bit)" "iPhone" "iPad" "iPad Retina"
然而,问题是:我似乎无法弄清楚如何在默认情况下启动模拟器(它似乎是iPhone Retina (4-inch)
模拟图像).相关输出cordova help
提供以下信息:
run [--debug|--release] [--device|--emulator|--target=FOO] [PLATFORM] ............................ deploys app on specified platform devices / emulators
我尝试过以下内容:
cordova run --debug --emulator=iPad iOS
其中有很多变种,但没有运气.每次它都在同一个模拟器中启动.
命令行工具的文档没有提供这方面的任何信息,并且广泛的Google搜索也未能提供任何信息.我错过了一些微不足道的事情吗?或者我想做一些奇怪的事情?我真的希望这里有人有这方面的经验,并且可以提供一些答案.
首先十分感谢!
编辑:忘了提及; 我在Mac上做这一切.如前所述,在Xcode中的不同仿真器/模拟器中运行应用程序工作正常.
要找出可用的模拟器图像,您可以使用它们列出它们
$ cordova emulate ios --list Available iOS Virtual Devices: iPhone-4s, 9.3 iPhone-5, 9.3 iPhone-5s, 9.3 iPhone-6, 9.3 iPhone-6-Plus, 9.3 iPhone-6s, 9.3 iPhone-6s-Plus, 9.3 iPad-2, 9.3 iPad-Retina, 9.3 iPad-Air, 9.3 iPad-Air-2, 9.3 iPad-Pro, 9.3
然后使用--target参数中的一个模拟器名称:
cordova emulate ios --target="iPhone-4s, 9.3" cordova emulate ios --target="iPad-Air-2, 9.3" cordova emulate ios --target="iPhone-6s, 9.3" cordova emulate ios --target="iPhone-6-Plus, 9.3"
重要说明在启动其他目标模拟器之前退出模拟器(在菜单栏上选择Simulator->Quit
)
考虑到您可能需要通过菜单退出iOS模拟器以从3.5英寸切换到4英寸iPhone.
动态列表可用于 platforms/ios/cordova/lib/list-emulator-images
不包括版本号
cordova run ios --target="iPhone-6s"
您可以通过直接使用ios-sim启动特定的模拟器并选择您的ios版本.
export appname="./platforms/ios/build/emulator/Hello World.app" ios-sim launch "$appname" --devicetypeid "com.apple.CoreSimulator.SimDeviceType.iPad-2, 8.0" --stderr ./platforms/ios/cordova/console.log --stdout ./platforms/ios/cordova/console.log
当我跑这个:
cordova emulate ios --target="iPad"
看着正在运行的进程,我看到了这一点(在一行上):
ios-sim launch ./platforms/ios/build/emulator/HelloWorld.app --stderr ./platforms/ios/cordova/console.log --stdout ./platforms/ios/cordova/console.log --family ipad --exit
进一步调查ios-sim,看起来有一些更具体的选项,特别是:
--devicetypeid <device type> The id of the device type that should be simulated (Xcode6+). Use 'showdevicetypes' to list devices. e.g "com.apple.CoreSimulator.SimDeviceType.Resizable-iPhone6, 8.0"
所以我按照它的建议做了并用"showdevicetypes"参数运行了ios-sim并得到了这个:
$ ios-sim showdevicetypes com.apple.CoreSimulator.SimDeviceType.iPhone-4s, 7.1 com.apple.CoreSimulator.SimDeviceType.iPhone-5, 7.1 com.apple.CoreSimulator.SimDeviceType.iPhone-5s, 7.1 com.apple.CoreSimulator.SimDeviceType.iPad-2, 7.1 com.apple.CoreSimulator.SimDeviceType.iPad-Retina, 7.1 com.apple.CoreSimulator.SimDeviceType.iPad-Air, 7.1 com.apple.CoreSimulator.SimDeviceType.iPhone-4s, 8.0 com.apple.CoreSimulator.SimDeviceType.iPhone-5, 8.0 com.apple.CoreSimulator.SimDeviceType.iPhone-5s, 8.0 com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus, 8.0 com.apple.CoreSimulator.SimDeviceType.iPhone-6, 8.0 com.apple.CoreSimulator.SimDeviceType.iPad-2, 8.0 com.apple.CoreSimulator.SimDeviceType.iPad-Retina, 8.0 com.apple.CoreSimulator.SimDeviceType.iPad-Air, 8.0 com.apple.CoreSimulator.SimDeviceType.Resizable-iPhone, 8.0 com.apple.CoreSimulator.SimDeviceType.Resizable-iPad, 8.0
正如csantanapr所说,你可以使用:
cordova emulate ios --target="iPhone-4s"
但是,在这种情况下,cordova(或PhoneGap或其他)项目将在iOS版本7.0.3的iPhone 4s模拟器上启动.
如果你想在同一个模拟器上启动项目,但是使用其他版本的iOS(7.1或8.0,如果它的版本存在于你的系统中)?
科西嘉,你可以像说cobberboy:
启动一个特定的模拟器,直接使用ios-sim选择你的ios版本.
但是你可以改进--target
cordova run
命令的选项.
首先,您必须确保系统上可用的目标iOS版本.
对于它使用cobberboy的答案:
$ ios-sim showdevicetypes
然后你需要打开文件your_project_dir/platforms/ios/cordova/lib/run.js
并找到如下代码行:
// validate target device for ios-sim // Valid values for "--target" (case sensitive): var validTargets = ['iPhone-4s', 'iPhone-5', 'iPhone-5s', 'iPhone-6-Plus', 'iPhone-6', 'iPad-2', 'iPad-Retina', 'iPad-Air', 'Resizable-iPhone', 'Resizable-iPad'];
使用iPhone-4s, 7.1
(或其他)简单地将其添加到数组validTargets
.
var validTargets = ['iPhone-4s', 'iPhone-4s, 7.1', 'iPhone-5', 'iPhone-5s', 'iPhone-6-Plus', 'iPhone-6', 'iPad-2', 'iPad-Retina', 'iPad-Air', 'Resizable-iPhone', 'Resizable-iPad'];
并在
cordova emulate ios --target="iPhone-4s, 7.1"
你的意思--target="iPhone-4s, 7.1"
是有效的.
而功能deployToSim
的run.js
:
function deployToSim(appPath, target) { // Select target device for emulator. Default is 'iPhone-6' if (!target) { target = 'iPhone-6'; console.log('No target specified for emulator. Deploying to ' + target + ' simulator'); } var logPath = path.join(cordovaPath, 'console.log'); var simArgs = ['launch', appPath, '--devicetypeid', 'com.apple.CoreSimulator.SimDeviceType.' + target, // We need to redirect simulator output here to use cordova/log command // TODO: Is there any other way to get emulator's output to use in log command? '--stderr', logPath, '--stdout', logPath, '--exit']; return spawn('ios-sim', simArgs); }
转换iPhone-4s, 7.1
到有效的论据com.apple.CoreSimulator.SimDeviceType.iPhone-4s, 7.1
进行ios-sim
.