Cordova: start specific iOS emulator image

前端 未结 10 2296
暗喜
暗喜 2020-12-07 07:07

I\'m developing a cross-platform mobile app using Cordova, focussing mainly on iOS in the development stage.

For my development process it would be ideal if I could

相关标签:
10条回答
  • 2020-12-07 07:27

    fastest output of devices list: $ instruments -s devices

    Just use the device name without the version.

    0 讨论(0)
  • 2020-12-07 07:27

    Different iphone and ipad simulator

    1. cordova run ios --list

    2. cordova emulate ios --target "iPhone-7"

    0 讨论(0)
  • 2020-12-07 07:29

    As say csantanapr you can use:

    cordova emulate ios --target="iPhone-4s"
    

    but, in this case cordova (or PhoneGap or other) project will be launched on iPhone 4s simulator with iOS version 7.0.3.

    If you want launch project on same simulator, but with other version iOS (7.1 or 8.0, if it versions exist in your system)?

    Of corse, you can do like say cobberboy:

    start a specific emulator and choose your ios version by directly using ios-sim.

    But you can improve --target option of cordova run command.

    At first you must ensure what target iOS version available on your system.

    For it use answer of cobberboy:

    $ ios-sim showdevicetypes
    

    Then you need to open the file your_project_dir/platforms/ios/cordova/lib/run.js and find lines of code like below:

    // 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'];
    

    For use iPhone-4s, 7.1 (or some other) simple add it to array 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'];
    

    And in

    cordova emulate ios --target="iPhone-4s, 7.1"
    

    your --target="iPhone-4s, 7.1" will be valid.

    And function deployToSim of 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);
    }
    

    convert iPhone-4s, 7.1 to valid argument com.apple.CoreSimulator.SimDeviceType.iPhone-4s, 7.1 for ios-sim.

    0 讨论(0)
  • 2020-12-07 07:29

    I can't comment on the answer above due to my low reputation, but the list of targets is available from:

    start-emulator 
    

    under

    your platform/ios/cordova/lib/
    

    Having said that, I cannot make the ipad retina emulator work...

    0 讨论(0)
  • 2020-12-07 07:36

    As of Xcode 8.3.2...

    Old thread, I know, but it seems, perhaps, that the answer has changed slightly. The hints from earlier posts in this thread helped, but so did reading the documentation included in the code, <cordova-project>/platforms/ios/cordova/lib/run.js

    Execute ./platforms/ios/cordova/lib/list-emulator-images to list the available emulator images. Do not include the version number on the end when making the cordova call to run in the desired emulator.

    cordova run ios --emulator --target="iPad-Air"
    

    See more

    0 讨论(0)
  • 2020-12-07 07:36

    Runs iOS simulator with web request based on already generated build for cordova application. Execute this request from browser opens simulator on mac with iPhone 8Plus version: http://hostname:3000/cordova/build/[xxxx-buildnumber]/emulate?target=iPhone-8-Plus

    0 讨论(0)
提交回复
热议问题