How to deploy Cordova app via CLI to a specified iPhone device?

10,997

Hi I'm an ionic developer, however i clearly use cordova. Let me try to help you.

Privet Sergey!

I use a shell script that uses ios-deploy node module that can deploy and debug through use of Xcode.

Firstly run this command to list all devices, you should see both of them ( FYI, is that normal to deploy to 2 devices at once using xcode? )

ios-deploy -c

For installation of ios-deploy , see (https://github.com/phonegap/ios-deploy)

Now for connecting and running commands to a specific device use this command:

ios-deploy  --id <device_id> --bundle my.app

There are shortcuts for this awesome command line tool.

    Usage: ios-deploy [OPTION]...
  -d, --debug                  launch the app in GDB after installation
  -i, --id <device_id>         the id of the device to connect to
  -c, --detect                 only detect if the device is connected
  -b, --bundle <bundle.app>    the path to the app bundle to be installed
  -a, --args <args>            command line arguments to pass to the app when launching it
  -t, --timeout <timeout>      number of seconds to wait for a device to be connected
  -u, --unbuffered             don't buffer stdout
  -n, --nostart                do not start the app when debugging
  -I, --noninteractive         start in non interactive mode (quit when app crashes or exits)
  -L, --justlaunch             just launch the app and exit lldb
  -v, --verbose                enable verbose output
  -m, --noinstall              directly start debugging without app install (-d not required)
  -p, --port <number>          port used for device, default: 12345
  -r, --uninstall              uninstall the app before install (do not use with -m; app cache and data are cleared)
  -1, --bundle_id <bundle id>  specify bundle id for list and upload
  -l, --list                   list files
  -o, --upload <file>          upload file
  -w, --download               download app tree
  -2, --to <target pathname>   use together with up/download file/tree. specify target
  -V, --version                print the executable version
  -e, --exists                 check if the app with given bundle_id is installed or not
Share:
10,997
Sergey Snegirev
Author by

Sergey Snegirev

CEO @ BranchTrack.com CTO @ www.intea.lv

Updated on June 14, 2022

Comments

  • Sergey Snegirev
    Sergey Snegirev almost 2 years

    I am working with latest Cordova (4.3) on OS X and I have 2 iPhones attached to my Macbook Pro. Whenever I want to test my app, I run the following command in Terminal:

    cordova run ios --device
    

    The script produces the following output in Terminal:

    ** BUILD SUCCEEDED **
    [....] Waiting up to 5 seconds for iOS device to be connected
    [....] Found iPhone 4S 'iPhone 4S' (0b2799xxxxx) connected through USB.
    [....] Found iPhone 4 (GSM) 'QA iPhone 4' (40daa94b6dc607595a570c0893ba54b185a85124) connected through USB.
    [....] Waiting for iOS device to be connected
    [....] Using iPhone 4S 'iPhone 4S' (0b27990xxxxxx) (0b2799xxxx).
    ------ Install phase ------
    [  0%] Found iPhone 4S 'iPhone 4S' (0b279904xxxxxxx) connected through USB, beginning install
    

    And then it proceeds to install the app on ONE of the iPhones, and opens up the lldb prompt. The 2nd iPhone remains dead and silent.

    When I exit the lldb (via 'exit', 'y'), the scripts shows an error:

    Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] y
    Error code 253 for command: ios-deploy with args: -d,-b,/Users/path_to_app/appname.app
    ERROR running one or more of the platforms: Error: /Users/path_to_app/platforms/ios/cordova/run: Command failed with exit code 2
    You may not have the required environment or OS to run this project
    

    I looked all over Cordova CLI documentation and Google but I cannot see how I can deploy an app to a specific physical iPhone device (not emulator!). On Android, I can use "cordova run android --target=06af27413440e95f", where the long number is the device id in adb. How do I do that for iPhones?

    I tried the following to no avail:

    cordova run ios --target='QA iPhone 4'
    cordova run ios --device='QA iPhone 4'
    cordova run ios --device --target='QA iPhone 4'