How do I reset the simulator used by an Xcode bot? - xcode

The simulator instance I'm using is sometimes left in an inconsistent state after a continuous integration run, how do I reset it?
It does not seem that resetting the simulator that runs in a normal user account on the build server will reset the simulator that is used by the Bots (which is run under the restricted _xcsbuild user.)

Inspired by this gist, run this script as a "Before Integration" trigger on your Bot:
/usr/bin/osascript -e 'tell application "iOS Simulator" to quit'
/usr/bin/osascript -e 'tell application "Simulator" to quit'
/usr/bin/xcrun simctl erase all
... and dupe radar 24091918 to add "all" as a valid argument to xcrun simctl shutdown.

Related

How to run Script from "Build Phases" section in archived (deployed) app?

so I'm trying to build a macOS menu bar app that executes a binary (a small server) and closes it when the app is closed. I added "path/to/server >/dev/null 2>&1 &" to the "Run Script"-section in "Build Phases" and it works perfectly when executing the app from Xcode. Now I wanted to store it locally in my Applications-Folder ("Archive" -> "Distribute App" -> "Copy App"). But when I start the app from there, the server does not start. I only found solutions for executing the script before archiving, but it needs to run every time I open the application. (macOS Ventura, Xcode 14)
What do I need to do?
Thanks a lot,
Nicolas

iOS simulator: double click home button does not work sometimes

With the iOS simulator version 10, double clicking the home button to bring up multitasking (running apps) sometimes does not respond. Even hitting (cmd + shift + h)x2 to simulate home button double click also works sometimes. I have verified this with a work mate and they have the same issue. I am not sure if this is a bug in the simulator or if there is a setting somewhere on for example the delay between the clicks? The answer from here did not make a difference.
I have this problem too when I want to close my app. So, I use command line instead:
xcrun simctl list | grep Booted
then copy simulator ID, and run this command to close app
xcrun simctl terminate <simulator ID> <your app bundle ID>
... or if you have only one simulator running, just type booted:
xcrun simctl terminate booted <your app bundle ID>
Enable this setting in the simulator hardware settings.
Hardware > Keyboard > Send Keyboard Shortcuts to Device
Command + Shift + H + H will no longer do anything BUT double tapping the home button on the simulator will start working as expected.

kill iOS Simulator from terminal

I'm trying to terminate the iOS Simulator from the terminal console (needed for integrating automatic UI Testing in Jenkins),but every time I try the command:
killall SimulatorBridge
a prompt waiting for action gets displayed:
The problem is that the simulator doesn't get dismissed until an action on the prompt is taken. How to get rid of it?
The proper way to shutdown simulators is xcrun simctl shutdown all.
I don't recommend shutting down simulators by killing CoreSimulator.
Simulator.app is just a viewer (as of Xcode 9). It does not need to be launched and so does not need to be shut down either. It will respond to devices booting and shutting down automatically.
You can also hold down Option when quitting to detach from running simulators without shutting them down. Check the checkbox to make that the default behavior.
Similarly you can hold down Control when closing a window via File, Close to get a similar choice when closing a single simulator's window.
Use killall "iPhone Simulator"
With XCode 6, use killall "iOS Simulator" (thanks #gempewsaw)
With XCode 7, use killall "Simulator" (thanks #Stanislaw)
With XCode 8, killing the Simulator process is sometimes not enough, also need to kill process com.apple.CoreSimulator.CoreSimulatorService (thanks #bensnider)
I agree with the answers above. Just wanted to add that I noticed my Jenkins job was failing when there was no simulator to kill. I got around this by adding it like this:
killall "iOS Simulator" || echo "No matching processes belonging to you were found"
Good luck with your ci!
Please try
killall -9 "iPhone Simulator"
You can kill Simulator running from commandline.
killall "Simulator" || true

jailbroke app on simulator?

I'm developing apps for jailbroken iPhone on Xcode. I'm using Xcode 4.2 and my iPhone OS is iOS6. I cannot connect my iPhone with XCode for testing because XCode 4.2 does not support iOS6.
Every time when I compile the code and try to run it on the simulator, I cannot get out of the sandbox. So I've tried to create an .ipa file, install it on iPhone and test it.
Is there any way to test jail broken apps on simulator?
It depends what kind of jailbreak functionality you're looking to test. I have a jailbreak app that accesses the full file system, and when I run it in the Simulator, I can access ALL the files on my Mac, not just from the Simulator's home directory (See pic here showing the Mac's Applications directory in Simulator). If this is something you have in your app, you could reconstruct the file system of your iPhone on your Mac and use that for testing. However, if you're doing something like accessing the iPhone's serial port, the Simulator obviously won't have that capability.
Alternatively, have you tried creating a post build script to install the .app file onto your iPhone via SSH? Here's the script I use (the variable IPOD is the device's IP local address in my WLAN, the others come from Xcode):
bundleid=`defaults read $BUILT_PRODUCTS_DIR/${WRAPPER_NAME}/Info.plist CFBundleIdentifier`
# kill if running, remove old version, copy new one and launch it
ssh -p $PORT root#$IPOD "killall $EXECUTABLE_NAME"
ssh -p $PORT root#$IPOD "rm -r /private/var/stash/Applications/$WRAPPER_NAME"
scp -P $PORT -r $BUILT_PRODUCTS_DIR/${WRAPPER_NAME} root#$IPOD://private/var/stash/Applications
ssh -p $PORT root#$IPOD "open $bundleid"
The open command is available on Cydia.
This is obviously a very simple script and there are probably better ways of doing it (like using dpkg), but it gets the job done for me.
You'll obviously need to have SSH installed and activated on your iPhone, and some other things like killall (all available in Cydia).

Xcode 4 Applescript to build and run the current target app

I'm looking for some applescript that would tell Xcode to run the current target.
I'd like to automate Xcode from textmate to provide "Run in simulator" and "Run on device".
This is as far as I got:
tell application "Xcode"
set myWorkspace to active workspace document
set myProject to the active project document of myWorkspace -- Can’t get active project document of workspace document "project.xcworkspace"
...
end tell
Creative use of the xcodebuild command line tool would very likely get you much further.

Resources