Launch XETbuild's RETINA Simulator for Continuous Integration

I perform automated tests of application modules under the CI environment for iPhone applications, and everything works fine using a command line such as:

xcodebuild -scheme "Tests" -configuration Debug -sdk iphonesimulator5.0 

This is great, but now I want to force the iPhone simulator to run in Retina mode, not standard standard mode.

I know that I can switch this using the hardware menu option, however I run it on a headless integration server, so I don't have this option.

What I would like to do is pass the switch on the command line, which says that the simulator starts in Retina mode.

I optimistically tried adding SimulateDevice = "iPhone (Retina)" to the xcodebuild command, but this does not seem to work.

Is it possible? At the moment I can not find a way.

If this is not possible, is there an alternative approach I can take?

+4
source share
7 answers

You must use AppleScript to change the value of SimulateDevice to com.apple.iphonesimulator.plist .

Here is an example that does this after asking the user to select the desired device type. You can change it to read the value from the command line or use "iPhone (Retina)" as the default value.

The following script changes the simulator to a value from the command line:

 on run argv set selectedDevice to item 1 of argv as string set thePListFolderPath to path to preferences folder from user domain as string set thePListPath to thePListFolderPath & "com.apple.iphonesimulator.plist" tell application "System Events" tell property list file thePListPath tell contents set value of property list item "SimulateDevice" to selectedDevice end tell end tell end tell end run 

And you can execute it from the terminal using the osascript :

 osascript myScript.scpt "iPhone (Retina)" 

or

 osascript myScript.scpt "iPhone" 

Edit

You can modify this script to run the default Retina simulator:

 set selectedDevice to "iPhone (Retina)" set thePListFolderPath to path to preferences folder from user domain as string set thePListPath to thePListFolderPath & "com.apple.iphonesimulator.plist" tell application "System Events" tell property list file thePListPath tell contents set value of property list item "SimulateDevice" to selectedDevice end tell end tell end tell 

Finally, note that changes to the "SimulateDevice" take effect when you start a new simulator.

+3
source

Another approach is as follows:

 defaults write com.apple.iphonesimulator "SimulateDevice" '"iPhone (Retina)"' 

However, as with sch's applescript approach, this does not seem to work when used as part of the build phase. Continuing the investigation ...

+5
source

For any script in Ruby, this is the method of installing the simulated device in the simulator:

  def set_simulated_device(simulated_device) current_simulated_device = `defaults read com.apple.iphonesimulator "SimulateDevice"`.chomp if current_simulated_device != simulated_device simulator_pid = `ps -ax|awk '/[i]Phone Simulator.app\\/Contents\\/MacOS\\/iPhone Simulator/{print $1}'`.chomp Process.kill('INT', simulator_pid.to_i) unless simulator_pid.empty? `defaults write com.apple.iphonesimulator "SimulateDevice" '"#{simulated_device}"'` end end 


List of arguments that can be used
"iPhone Retina (3.5 inches)"
"iPhone Retina (4-inch)"
"iPhone Retina (4-inch 64-bit)"
"IPad"
"iPad Retina"
"iPad Retina (64-bit)"

+2
source

You can do it from the iPhone Simulator binary file

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone\Simulator -SimulateDevice "iPhone Retina (4-inch)"

for other versions:

  • "iPhone Retina (3.5 inches)"
  • "iPhone Retina (4-inch)"
  • "iPhone Retina (4-inch 64-bit)"
  • "IPad"
  • "iPad Retina"
  • "iPad Retina (64-bit)"
0
source

not reporting that some answers are wrong .. but this worked for ios 7

 -- START:choose.sim.device on run argv --set simType to item 1 of argv tell application "iPhone Simulator" activate end tell set simType to "Ipad Retina (64-bit)" tell application "System Events" tell process "iOS Simulator" tell menu bar 1 -- Hardware menu bar item tell menu bar item 5 -- Hardware menu tell menu 1 -- Device menu item tell menu item 1 -- Device sub menu tell menu 1 click menu item simType end tell end tell end tell end tell end tell end tell end tell -- END:choose.sim.device -- Need to show the simulator again after changing device, -- or else the simulator be hidden when launched by instruments -- for some odd reason. tell application "System Events" set visible of process "iPhone Simulator" to true end tell -- START:choose.sim.device end run -- END:choose.sim.device 

Note: its not an “iPad” its an “iPad”

0
source

Pro-tip, create an alias.

 alias ios="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateDevice" 

Example:

 ios "iPhone Retina (3.5-inch)" ios "iPhone Retina (4-inch)" ios "iPhone Retina (4-inch 64-bit)" ios "iPad" ios "iPad Retina" ios "iPad Retina (64-bit)" 
0
source

You can specify a device with the -destination flag:

 xcodebuild -scheme "Tests" \ -configuration Debug \ -destination "platform=iOS Simulator,name=iPhone 6" 
0
source

Source: https://habr.com/ru/post/1399992/


All Articles