2012-12-14 74 views
9

我想使用包含的./emulator命令與Cordova/PhoneGap從命令行在iPad模擬器中運行我的應用程序。使用Cordova/PhoneGap模擬器命令模擬iPad

的基本說明在這裏:

我已經安裝了iOS模擬器從這裏:

的文件說它支持從命令行模擬iPad。但是,它默認打開iPhone並將設備更改爲「iPad」關閉應用程序(並且未安裝在主屏幕上)。我搜索了但無法找到要啓動的文檔來模擬iPad。

如何運行Cordova ./emulator命令以打開iPad?

+0

http://docs.phonegap.com/en/2.2.0/guide_command-line_index.md。html#命令行%20Usage_ios – F481

+0

謝謝,F481,但我鏈接到我的問題中的URL。它沒有說如何將模擬器作爲iPad(而不是iPhone)來啓動。 –

回答

8

Cordova emulate腳本只是您可以直接從命令行使用的ios-sim命令的包裝。假設你的當前工作目錄是一個與它的模擬腳本,可以在模擬器中的iPad模式下啓動您的構建:

ios-sim launch ../build/myApp.app --family ipad --stderr console.log --stdout console.log & 

下無疑是天真的(我不知道殼 - 腳本),但我已經破解了emulate腳本以支持第二個命令行參數,該參數允許我指定設備系列。您可能不知道該腳本已經接受了第一個參數,該參數允許您指定項目文件的路徑,因爲如果未指定該參數,它將計算出路徑。

更新你的腳本的版本具有以下(GitHub上叉here):

#! /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 

然後就可以像這樣運行腳本(假定您的當前工​​作目錄是包含腳本的科爾多瓦目錄):

./emulate ../build/myApp.app ipad 

如果你總是要測試的iPad和你不喜歡有指定您的應用程序的路徑每一次,你可能只是硬編碼您的首選器件系列到腳本像這樣和啓動模擬器作爲y OU此前已做:

ios-sim launch "$APP_PATH" --family ipad --stderr "$CORDOVA_PATH/console.log" --stdout "$CORDOVA_PATH/console.log" & 
18

這可能是因爲你使用的是舊版本的PhoneGap /科爾多瓦,但在3.4以下的工程版本對我來說:

cordova emulate ios --target="iPad" 
+0

有沒有指向文檔的鏈接? – Asaf

+0

這個工作,但你知道如何與iPad視網膜運行? target =「iPad Retina」和--target =「iPad(Retina)」似乎不起作用 – StarQuake

+0

這裏用'cordova run ios --target =「ipad(retina)」'參見https://github.com/ apache/cordova -ios/blob/7c154550183fc71d13b6c612bad4c5c7c8154dd9/bin/templates/scripts/cordova/run#L84 – jujule

0

對我來說,所有提到的這裏的選項沒有工作,我有這個命令來調用它顯示了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'sios-sim showdevicetypes