我想使用包含的 ./emulator 命令和 Cordova/PhoneGap 从命令行在 iPad 模拟器中运行我的应用程序。
基本说明在这里:
我从这里安装了 iOS 模拟器:
文档说它支持从命令行模拟 iPad。但是,默认情况下它会在 iPhone 上打开,将设备更改为“iPad”会关闭应用程序(并且它不会安装在主屏幕上)。我已经搜索但找不到要启动以模拟 iPad 的文档。
如何运行 Cordova ./emulator 命令以打开 iPad?
我想使用包含的 ./emulator 命令和 Cordova/PhoneGap 从命令行在 iPad 模拟器中运行我的应用程序。
基本说明在这里:
我从这里安装了 iOS 模拟器:
文档说它支持从命令行模拟 iPad。但是,默认情况下它会在 iPhone 上打开,将设备更改为“iPad”会关闭应用程序(并且它不会安装在主屏幕上)。我已经搜索但找不到要启动以模拟 iPad 的文档。
如何运行 Cordova ./emulator 命令以打开 iPad?
可能是您使用的是旧版本的 phonegap/cordova,但在 3.4 版中,以下对我有用:
cordova emulate ios --target="iPad"
Cordovaemulate
脚本只是ios-sim
您可以直接从命令行使用的命令的包装器。假设您当前的工作目录是其中包含 emulate 脚本的目录,您可以使用以下命令在 iPad 模式下在模拟器中启动构建:
ios-sim launch ../build/myApp.app --family ipad --stderr console.log --stdout console.log &
以下内容无疑是幼稚的(我不知道 shell 脚本),但我已经破解了emulate
脚本以支持第二个命令行参数,该参数允许我指定设备系列。您可能不知道脚本已经接受了第一个参数,该参数允许您指定项目.app
文件的路径,因为如果未指定参数,它会计算出路径。
使用以下内容更新您的脚本版本(此处为 GitHub fork ):
#! /bin/sh
#
# Licensing info removed for brevity
#
set -e
XCODE_VER=$(xcodebuild -version | head -n 1 | sed -e 's/Xcode //')
XCODE_MIN_VERSION="4.5"
if [[ "$XCODE_VER" < "$XCODE_MIN_VERSION" ]]; then
echo "Cordova can only run in Xcode version $XCODE_MIN_VERSION or greater."
exit 1
fi
CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd -P)
PROJECT_PATH="$(dirname "$CORDOVA_PATH")"
XCODEPROJ=$( ls "$PROJECT_PATH" | grep .xcodeproj )
PROJECT_NAME=$(basename "$XCODEPROJ" .xcodeproj)
APP_PATH=$1
DEVICE_FAMILY=$2
if [ $# -lt 1 ]; then
APP_PATH="$PROJECT_PATH/build/$PROJECT_NAME.app"
DEVICE_FAMILY=iphone
fi
if [ ! -d "$APP_PATH" ]; then
echo "Project '$APP_PATH' is not built. Building."
$CORDOVA_PATH/build || exit $?
fi
if [ ! -d "$APP_PATH" ]; then
echo "$APP_PATH not found to emulate."
exit 1
fi
# launch using ios-sim
if which ios-sim >/dev/null; then
ios-sim launch "$APP_PATH" --family "$DEVICE_FAMILY" --stderr "$CORDOVA_PATH/console.log" --stdout "$CORDOVA_PATH/console.log" &
else
echo -e '\033[31mError: ios-sim was not found. Please download, build and install version 1.4 or greater from https://github.com/phonegap/ios-sim into your path. Or "brew install ios-sim" using homebrew: http://mxcl.github.com/homebrew/\033[m'; exit 1;
fi
然后,您可以像这样运行脚本(假设您当前的工作目录是包含脚本的 cordova 目录):
./emulate ../build/myApp.app ipad
如果您总是要在 iPad 上进行测试,并且您不想每次都指定应用程序的路径,您可以像这样将首选设备系列硬编码到脚本中,然后像以前一样启动模拟器:
ios-sim launch "$APP_PATH" --family ipad --stderr "$CORDOVA_PATH/console.log" --stdout "$CORDOVA_PATH/console.log" &
对我来说,这里提到的所有选项都不起作用,我不得不用这个命令调用它来显示 iPad Retina:
``ios-sim launch [DIR_OF_APP]platforms/ios/build/emulator/My-App.app --devicetypeid "com.apple.CoreSimulator.SimDeviceType.iPad-Retina, 8.2"
检索所有devicetypeid's
类型ios-sim showdevicetypes