PhoneGap - Select specific hardware device in iOS simulator - ios

I am developing a PhoneGap app on a Mac. I can spin up the iOS simulator by building, then running the following command:
phonegap run ios
The issue i'm having is that running this command always spins up iOS 7.0.3 (11B507) on a simulated iPhone Retina (3.5-inch). I'd like to be able to test different devices (iPad/previous versions of iOS) but see no way of specifying the device via the run command and haven't added any code to specify device or version.
Is there any way to specify which hardware device to use when debuggion such apps via the iOS simulator?
Thank you

You can use the cordova command instead of phonegap to run a specific device. First install cordova globally
sudo npm install -g cordova
Then you can check the available devices for the IOS Simulator with the command
ios-sim showdevicetypes
This will give you a list such as the following:
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
Finally, to select one device to run on the Simulator use the following command replacing the string for the device's name of your choice:
cordova emulate ios --target="device-name"
Examples:
cordova emulate ios --target="iPhone-5s"
cordova emulate ios --target="iPad-Retina"

Related

Problems trying to run Ionic App in iOS Simulator

Since i upgrade Xcode to 12.2 version, i start having problems when i try to run my ionic app in iOS Simulator.
App build successfully but couldn't start in simulator, in physical device works properly. I obtain the next error message
No target specified for emulator. Deploying to undefined simulator.
Device type "com.apple.CoreSimulator.SimDeviceType.undefined" could not be found.
Thanks
I have also faced same problem after updating the Mojave.
You can launch the simulator by specifying complete path to CoreSimulator for target attribute. Try following commands
$ ionic cordova emulate ios --livereload --consolelogs --target="iPhone-6,com.apple.CoreSimulator.SimRuntime.iOS-12-2"
$ ionic cordova emulate ios --livereload --consolelogs --target="iPhone-6,com.apple.CoreSimulator.SimRuntime.iOS-12-2" --buildFlag="-UseModernBuildSystem=0"
Let me know if it didn't work for you.

Xcode device list is empty in ionic/cordova project

No matter what I try I can't get access to the Xcode simulators from my ionic/cordova project. Xcode Command Line Tool is installed.
cordova run ios --list
returns
Available ios devices:
Available ios virtual devices:
ionic cordova emulate ios --list
returns
Available ios virtual devices:
I have all the simulators in Xcode and it's working fine when Im opening the project in Xcode and run the simulators manually.
The consequences of this is that I cant run my app with livereload from the terminal:
ionic cordova emulate --livereload ios -- --buildFlag="-UseModernBuildSystem=0" --target="iPhone-X, 12.1"
returns
Device id for device name "iPhone X" and runtime "iOS 12.1" could not be found, or is not available.
This is a bug related to the new version of XCode. I had the same problem. I would advise you to uninstall and reinstall XCode but I don't think it will work.
I solved (dirty fix) my problem by applying what ejerskov says here: https://github.com/ios-control/ios-sim/issues/246
On platforms/ios/cordova/node_modules/ios-sim/src/lib.js
I have changed
available_runtimes[ runtime.name ] = (runtime.availability === '(available)');
to
available_runtimes[ runtime.identifier ] = (runtime.availability === '(available)');
Otherwise I think we should wait for a new release of ios-sim and cordova-ios...

Test app on iOS 7.1

I need to test my app on iOS 7.1 but ran out of options.
My setup:
MacBook running El Capitan Xcode 7
No physical devices running iOS 7
I cant run the iOS 7 simulator - the simulator says that the runtime cannot be found and I cannot download iOS 7 from "downloads.
Do you have any suggestions?
My adviceļ¼š
(Remind: my English is limited, my expression is not very good!)
1.We can use Xcode7 to compiler to generate debug app
2.Use the xcode - select switch commandline tool to Xcode6.4
3.Run xcode6.4 iOS7 simulator
4.Using xcrun simctl installed test app to xcode6.4 iOS7 simulator
5.Run to check the effect (can't debugging)

How to run ios 8.4.1 device into xcode 6.0.1?

i can't access my device
My Device Version is->8.4.1
My Xcode deployment Version is ->8.0(maximum version),when i try to run its give me error message [may be running a version of iOS that is not supported by this version of Xcode].
Is there any possibility to run my device.
If you're running iOS 8.4.1 on your phone/simulator, then you'll need to upgrade to Xcode 6.4, which contains the iOS 8.4 SDK.

Cordova: start specific iOS emulator image

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 start my Cordova app directly from the command line and have it load into a specified emulator. I can do this by running the following from the project root directory:
$cordova run --debug --emulator iOS
This works fine, and results in an iOS-simulator running my app in a simulated iPhone 4 Retina with iOS 7.0.3
Besides this simulated device, I would also like to test on (for instance) an iPad. I have these emulation images installed, and I can start my app in them manually in Xcode. Also, the command list-emulator-images (located in project_dir/platforms/ios/cordova/lib) gives the following output:
"iPhone Retina (3.5-inch)"
"iPhone Retina (4-inch)"
"iPhone Retina (4-inch 64-bit)"
"iPhone"
"iPad"
"iPad Retina"
However, the thing is: I can't seem to figure out how to start the emulator in anything other than the default (which appears to be the iPhone Retina (4-inch) emulation image). The relevant output of cordova help gives the following information:
run [--debug|--release]
[--device|--emulator|--target=FOO]
[PLATFORM] ............................ deploys app on specified platform devices / emulators
I've tried things like the following:
cordova run --debug --emulator=iPad iOS
And many variations thereof, but no luck. Every time it starts in the same emulator.
The documentation for the command-line tool doesn't offer any information in this regard, and an extensive Google-search also failed to turn up anything. Am I missing something trivial? Or am I trying to do something weird? I really hope someone here has experience with this, and can provide some answers.
Thanks very much in advance!
edit: forgot to mention explicitly; I'm doing all this on a Mac. As mentioned earlier, running the app in different emulators/simulators in Xcode works fine.
To find out what are the simulator images available you can use to list them
$ 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
Then use one of the simulator names in the --target parameter:
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"
Important Quit the simulator before launching a different target simulator (On Menu bar select Simulator->Quit)
Take into account that you may need to quit the iOS simulator via menu to switch from 3.5 to 4 inch iPhone.
dynamic list is available in platforms/ios/cordova/lib/list-emulator-images
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.
TL;DR
You can start a specific emulator and choose your ios version by directly using ios-sim.
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
Details
When I ran this:
cordova emulate ios --target="iPad"
and looked at the processes running, I saw this (on a single line):
ios-sim launch ./platforms/ios/build/emulator/HelloWorld.app
--stderr ./platforms/ios/cordova/console.log
--stdout ./platforms/ios/cordova/console.log
--family ipad
--exit
Investigating further into ios-sim, it looks like there are some more specific options, particularly:
--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"
So I did as it suggested and ran ios-sim with a "showdevicetypes" argument and got this:
$ 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
Don't include version number
cordova run ios --target="iPhone-6s"
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
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...
fastest output of devices list:
$ instruments -s devices
Just use the device name without the version.
Now is:
cordova run ios --list
Available ios devices:
Available ios virtual devices:
Apple-TV-1080p, tvOS 14.3
Apple-TV-4K-4K, tvOS 14.3
Apple-TV-4K-1080p, tvOS 14.3
Apple-Watch-Series-5-40mm, watchOS 7.2
Apple-Watch-Series-5-44mm, watchOS 7.2
Apple-Watch-Series-6-40mm, watchOS 7.2
Apple-Watch-Series-6-44mm, watchOS 7.2
iPhone-8, 14.3
iPhone-8-Plus, 14.3
iPhone-11, 14.3
iPhone-11-Pro, 14.3
iPhone-11-Pro-Max, 14.3
iPhone-SE--2nd-generation-, 14.3
iPhone-12-mini, 14.3
iPhone-12, 14.3
iPhone-12-Pro, 14.3
iPhone-12-Pro-Max, 14.3
iPod-touch--7th-generation-, 14.3
iPad-Pro--9-7-inch-, 14.3
iPad-Pro--11-inch---2nd-generation-, 14.3
iPad-Pro--12-9-inch---4th-generation-, 14.3
iPad--8th-generation-, 14.3
iPad-Air--4th-generation-, 14.3
And:
cordova run ios --target="iPad-Pro--12-9-inch---4th-generation-, 14.3"
In Cordova 10.0.0
Different iphone and ipad simulator
cordova run ios --list
cordova emulate ios --target "iPhone-7"
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
#Birja's answer is working right now but the run command he used finally is still wrong so here the right answer:
To list all the devices available in simulator cordova run ios --list
It will result in something like this:
Available ios devices:
Available ios virtual devices:
Apple-TV-1080p, tvOS 12.2
Apple-Watch-Series-2-38mm, watchOS 5.2
iPhone-5s, 12.2
iPhone-6, 12.2
iPad-Air-2, 12.2
iPad--5th-generation-, 12.2
iPad-Pro--9-7-inch-, 12.2
iPad-Pro, 12.2
iPad-Pro--12-9-inch---2nd-generation-, 12.2
iPad-Pro--10-5-inch-, 12.2
iPad--6th-generation-, 12.2
iPad-Pro--11-inch-, 12.2
iPad-Pro--12-9-inch---3rd-generation-, 12.2
cordova run ios --target "iPad-Pro, 12.2" Use any target from the above. To run in simulator.

Resources