7

Since iOS 8 was released the default device type for simulator became iPhone 6. And even if I manually change the device type using Hardware > Device menu, on the next launch (using rake simulator) the simulator will revert to iPhone 6.

I wonder if there is any rake options, or some other settings to force the device type.

PS. I know that there are ways to force a non-retina iPhone and a way to launch the iPad simulator instead of the iPhone one, but I'm interested in selecting between 5/6/6+.

Thanks

Jeremy Huddleston Sequoia
  • 22,938
  • 5
  • 78
  • 86
Dmitry Sokurenko
  • 6,042
  • 4
  • 32
  • 53

4 Answers4

18

I found that the easiest way to do this is to add the following to the end of your Rakefile

desc "Run simulator on iPhone"
task :iphone4 do
    exec 'bundle exec rake device_name="iPhone 4s"'
end

desc "Run simulator on iPhone"
task :iphone5 do
    exec 'bundle exec rake device_name="iPhone 5"'
end

desc "Run simulator on iPhone"
task :iphone6 do
    exec 'bundle exec rake device_name="iPhone 6"'
end

desc "Run simulator in iPad Retina" 
task :retina do
    exec 'bundle exec rake device_name="iPad Retina"'
end

desc "Run simulator on iPad Air" 
task :ipad do
    exec 'bundle exec rake device_name="iPad Air"'
end

Then you can run rake iphone5 in your terminal and it will open the simulator for that device.

kobaltz
  • 6,980
  • 1
  • 35
  • 52
12

Run /Applications/Xcode.app/Contents/Developer/usr/bin/simctl list (or /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/simctl list for older versions of Xcode.

show your simulators following is my simulator devices

== Devices == -- iOS 7.0 -- -- iOS 7.1 -- iPhone 5s (971DB3D4-7FF4-4005-A11D-11541ED79193) (Shutdown) -- iOS 8.0 -- iPhone 5s (EE64F798-6CB9-40B1-8B19-30727C3CA538) (Shutdown) iPhone 6 Plus (D9F2BEEE-D341-4080-8A49-24AB6FACD9D9) (Shutdown) iPhone 6 (81229508-4D35-4BEE-B616-FB99FDC6BCDD) (Booted) iPad 2 (F2484155-E4A2-44E9-A113-AAF4B9A83717) (Shutdown) Resizable iPhone (B762046B-1273-4638-B0ED-A7827A822BDD) (Shutdown) Resizable iPad (AACAB77A-12BD-43F3-A847-3D11575F3BF3) (Shutdown)

if you want run iPhone 5s as IOS 7.1 (You must set app.deployment_target = '7.1'),you can do it like
rake device_name="iPhone 5s (971DB3D4-7FF4-4005-A11D-11541ED79193)"

fabi
  • 2,978
  • 1
  • 19
  • 23
zhulinpinyu
  • 599
  • 7
  • 12
  • 6
    Thanks, that's exactly what I was looking for. But setting the device name like `device_name="iPhone 5s (F1B3E385-4031-4858-8FD0-50D5F709893A)"` didn't work for me (it always revert to iPhone 4s in that case). While specifying just the device name like `device_name="iPhone 5s"` worked well. – Dmitry Sokurenko Oct 10 '14 at 11:51
  • `simctl` is now found at /Applications/Xcode.app/Contents/Developer/usr/bin/simctl – Andrew Aug 22 '16 at 09:10
  • In newer versions of Xcode (e.g. Xcode 11) use: `xcrun simctl list` to get the list of devices. – Andrew Oct 17 '19 at 19:51
1

In your rake file before "Motion::App" section, do the following

ENV['device_name'] ||= 'iPhone 4s'

Or specify the name of any other device in the simulator device list.

1

Tested in 2021, you only need to use something like:

rake device_name="iPad (8th generation)"