In Android I can run this to start emulator
emulator #NAME
and this to wait for it to load completely and be ready to use
adb wait-for-device
Is there an equivalent for iOS Simulator on Mac? I use default Xcode Simulator. So start of simulator
xcrun simctl boot deviceID
and wait for it to load completely (just an example of what I'm thinking of)
xcrun simctl wait deviceId
There is a not-exactly-documented simctl command of xcrun simctl bootstatus deviceID
It doesn't appear in the normal output of xcrun simctl help, but it does have xcrun simctl help bootstatus
From my own playing with it, if you call it, when the bootstatus command exits, your simulator should be fully operational. But since it isn't exactly documented your mileage may vary.
xcrun simctl help bootstatus
Checks device boot status.
Usage: simctl bootstatus <device> [-bc]
-b Boot the device if it isn't already booted.
-c Continuously monitor boot status through multiple boot/shutdown cycles.
Monitors the specified device and prints boot status information until the device finishes booting. You can safely call this before you attempt to start booting the device.
/usr/bin/xcrun simctl bootstatus 88668721-0DF0-4167-8F3E-37190E8099C1
Monitoring boot status for AutomationDevice - iPad Air 2 - iOS 11.4 (88668721-0DF0-4167-8F3E-37190E8099C1).
[2019-05-23 03:50:56 +0000] Status=2, isTerminal=NO, Elapsed=00:00.
Waiting on Data Migration
Reason:(null)
Migration Elapsed:00:00 seconds
[2019-05-23 03:50:56 +0000] Status=2, isTerminal=NO, Elapsed=00:01.
Waiting on Data Migration
Reason:Running plugin com.apple.MobileContainerManager.ContainerMigrator (ContainerMigrator.migrator, user-agnostic)
Migration Elapsed:00:00 seconds
[spaaaaaaam...]
[2019-05-23 03:51:06 +0000] Status=2, isTerminal=NO, Elapsed=00:11.
Waiting on Data Migration
Reason:Running plugin com.apple.iTunesStore.migrator (iTunesStore.migrator)
Migration Elapsed:00:10 seconds
[2019-05-23 03:51:08 +0000] Status=1, isTerminal=NO, Elapsed=00:12.
Waiting on BackBoard
[2019-05-23 03:51:12 +0000] Status=4, isTerminal=NO, Elapsed=00:16.
Waiting on System App
[2019-05-23 03:51:12 +0000] Status=4294967295, isTerminal=YES, Elapsed=00:17.
Finished
I did find an answer which works great for me. I am using "xcrun simctl spawn <UDID> launchctl print system | grep com.apple.springboard.services" and looking for these values in the output:
"M A com.apple.springboard.services"
"U A com.apple.backboardd"
"M D com.apple.medialibraryd"
"M A com.apple.mobile.installd"
Related
it says I can use group identifier to get exactly the group I want:
➜ ~ xcrun simctl get_app_container booted
Print the path of the installed app's container
Usage: simctl get_app_container <device> <app bundle identifier> [<container>]
container Optionally specify the container. Defaults to app.
app The .app bundle
data The application's data container
groups The App Group containers
<group identifier> A specific App Group container
^^^^^^^^^^^^^^^^^^
I believe this's the "group identifier":
➜ ~ xcrun simctl get_app_container booted com.apple.DocumentsApp groups
group.com.apple.DocumentManager /Users/zcfan/Library/Developer/CoreSimulator/Devices/E94453B7-DF52-4A88-AE9E-C1A752DFB613/data/Containers/Shared/AppGroup/4818FE0A-BC9B-4F13-A39C-71C162E76616
group.com.apple.FileProvider.LocalStorage /Users/zcfan/Library/Developer/CoreSimulator/Devices/E94453B7-DF52-4A88-AE9E-C1A752DFB613/data/Containers/Shared/AppGroup/6EE8B2AE-4CE2-4D07-9198-88E80455FF03
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
But if I call with it, simctl just print the help message again:
➜ ~ xcrun simctl get_app_container booted com.apple.DocumentsApp group.com.apple.FileProvider.LocalStorage
Print the path of the installed app's container
Usage: simctl get_app_container <device> <app bundle identifier> [<container>]
container Optionally specify the container. Defaults to app.
app The .app bundle
data The application's data container
groups The App Group containers
<group identifier> A specific App Group container
I tried other combinations too, same result:
xcrun simctl get_app_container booted com.apple.DocumentsApp group group.com.apple.FileProvider.LocalStorage
xcrun simctl get_app_container booted com.apple.DocumentsApp group.com.apple.FileProvider.LocalStorage
xcrun simctl get_app_container booted com.apple.DocumentsApp groups LocalStorage
xcrun simctl get_app_container booted com.apple.DocumentsApp group LocalStorage
xcrun simctl get_app_container booted com.apple.DocumentsApp LocalStorage
xcrun simctl get_app_container booted com.apple.DocumentsApp groups com.apple.FileProvider.LocalStorage
xcrun simctl get_app_container booted com.apple.DocumentsApp group com.apple.FileProvider.LocalStorage
xcrun simctl get_app_container booted com.apple.DocumentsApp com.apple.FileProvider.LocalStorage
I couldn't find any group identifier demo anywhere, is this option really working? Am I using the wrong identifier? A working demo would be great, thank you.
For now I have to manipulate the result of groups to get what I want:
xcrun simctl get_app_container booted com.apple.DocumentsApp groups | grep LocalStorage | awk -F'\t' '{print $2}'
It gives me the path of "On My Phone" filesystem of simulator:
Open it with Finder, I can do whatever I want to simulator FS.
open "`xcrun simctl get_app_container booted com.apple.DocumentsApp groups | grep LocalStorage | awk -F'\t' '{print $2}'`/File Provider Storage" -a Finder
Please note, I'm looking for /Applications/Xcode.app/Contents/Developer/usr/bin/instruments util (lower-case), not the Instruments app which can be found in Xcode.app/Contents/Applications.
I have both Xcode12 and Xcode13-beta-5 on my computer.
When run xcrun instruments -w <device id>, Xcode13 says xcrun: error: Failed to locate 'instruments'.
Locating the "instruments" in Xcode12:
olia#Olhas-MacBook-Pro % ls /Applications/Xcode.app/Contents/Developer/usr/bin/*instruments*
# output ✅
/Applications/Xcode.app/Contents/Developer/usr/bin/instruments
Locating the "instruments" in Xcode13:
olia#Olhas-MacBook-Pro % ls /Applications/Xcode-beta.app/Contents/Developer/usr/bin/*instruments*
# output ❌
zsh: no matches found: /Applications/Xcode-beta.app/Contents/Developer/usr/bin/*instruments*
Here, Xcode-beta.app is Xcode13, and Xcode.app is Xcode12.
There's no "instruments" util because it was deprecated in Xcode12, and in Xcode13 it seems to be removed.
Apple recommends using xcrun xctrace instead of xcrun instruments in Xcode12.
But as command xcrun instruments -w is for pre-launching Simulator, xctrace doesn't apply there.
We can run smth like
open -a Simulator.app --args -CurrentDeviceUDID <device id>
haha ~, I copied Xcode 's instruments to Xcode13 's /Applications/Xcode.app/Contents/Developer/usr/bin/ , then run react-native run-ios successful.
For me I needed to upgrade react-native using:
yarn upgrade react-native
Trying to create a new iOS simulator via the command line I ran
$ xcrun simctl list devicetypes runtimes
which gave me
iPhone SE (1st generation) (com.apple.CoreSimulator.SimDeviceType.iPhone-SE)
But when I tried to install the simulator I keep getting
Invalid runtime: com.apple.CoreSimulator.SimRuntime.iOS-13
I tried
$ xcrun simctl create 'iPhone SE (1st generation)' com.apple.CoreSimulator.SimDeviceType.iPhone-SE com.apple.CoreSimulator.SimRuntime.iOS-13
and
xcrun simctl create "iPhone SE (1st generation)" "com.apple.CoreSimulator.SimDeviceType.iPhone-SE" "com.apple.CoreSimulator.SimRuntime.iOS-13"
I also tried iOS 14 but the same issue occurred
$ xcrun simctl create ... com.apple.CoreSimulator.SimRuntime.iOS-14
Found the answer here
run
$ xcrun simctl create "MY-iPhone-SE-1stGen" "iPhone SE (1st generation)" iOS13
which will return a device uuid like
47F03253-EAA7-4682-80BA-C6769471993D
then to boot up the simulator you have use the device uuid to run
$ xcrun simctl boot 47F03253-EAA7-4682-80BA-C6769471993D
In the Xcode device drop down list you will see
MY-iPhone-SE-1stGen
FYI you can use whatever name you want in place of MY-iPhone-SE-1stGen
I'm trying to automate the functional testing I have in my project. For this, I use Jenkins and run the test tasks using the post-receive git hook. The job is properly invoked, but before the tests are run, I need to erase the simulators in order to tests first time startup of the app. I do the following:
#!/bin/bash --login
# simulator we want
sim="iPhone 6"
# close the iOS simulator if open
echo "Trying to close iOS Simulator"
osascript -e 'tell app "iOS Simulator" to quit'
# find all booted devices
booted=( $(xcrun simctl list | sed -n 's/.*(\(.*\)) (Booted)/\1/p') )
if [ ${#booted[#]} != 0 ]; then
echo 'Found the following booted devices:'
for device in ${booted[#]}
do
echo $device
done
else
echo 'There are no booted devices, skipping'
fi
# shutdown all of them to be able to erase them
for device in ${booted[#]}
do
echo "Trying to shutdown $device"
xcrun simctl shutdown $device
echo "Done"
done
# sanity check, all devices should be shutdown
booted=( $(xcrun simctl list | sed -n 's/.*(\(.*\)) (Booted)/\1/p') )
if [ ${#booted[#]} != 0 ]; then
echo 'Even though we shut down all the devices, some devices are still booted:'
for device in ${booted[#]}
do
echo $device
done
exit 1
fi
# erase the device so we can test index page and tutorial
allDevices=( $(xcrun simctl list | sed -En 's/.* \((.*)\) \((Shutdown)\)/\1/p') )
for device in ${allDevices[#]}
do
echo "Erasing device $device"
xcrun simctl erase $device
echo
done
# sanity check, all devices should be shutdown
booted=( $(xcrun simctl list | sed -n 's/.*(\(.*\)) (Booted)/\1/p') )
if [ ${#booted[#]} != 0 ]; then
echo 'Even though we shut down all the devices, some devices are still booted:'
for device in ${booted[#]}
do
echo $device
done
exit 1
fi
echo device list:
echo $(xcrun simctl list)
dev=( $(xcrun simctl list | sed -En 's/'"$sim"' \((.*)\) \((Shutdown)\)/\1/p') )
echo Booting the device $dev
xcrun simctl boot $dev
# clean is not good enough, need to remove DerivedData contents manually
rm -rf ~/Library/Developer/Xcode/DerivedData
/usr/local/bin/xctool -workspace MyApp.xcworkspace -scheme MyApp_QA2 clean
xcodebuild -workspace MyApp.xcworkspace -scheme MyApp_QA2 -destination 'platform=iOS Simulator,name=iPhone 6,OS=8.1' test | xcpretty -c -r html
When I run this, I get:
These lines are responsible for booting:
dev=( $(xcrun simctl list | sed -En 's/'"$sim"' \((.*)\) \((Shutdown)\)/\1/p') )
echo Booting the device $dev
xcrun simctl boot $dev
So, I comment them, but then the build fails with:
2015-03-10 09:56:13.036 xcodebuild[84840:4008451] [MT]
iPhoneSimulator: Unable to connect to
"com.apple.instruments.deviceservice.lockdown" (Error
Domain=com.apple.CoreSimulator.SimError Code=146 "Unable to lookup in
current state: Shutdown" UserInfo=0x7fbcb2f00af0
{NSLocalizedDescription=Unable to lookup in current state: Shutdown})
Looks to me like Xcode and simctl can't agree which one should be responsible for booting the correct sim. Any ideas?
You can launch the simulator with xcrun instruments -w "iPhone 5 (8.4 Simulator)"
and to shut down the simulator with killall "iOS Simulator"
In Xcode 6 and Xcode 7, Simulator.app is responsible for booting the device it uses. If you use simctl to boot the device, it will not be usable by Simulator.app in that state because it will be booted to a headless state.
I launch my iOS app on the device (not simulator) with the following command (app is already installed).
instruments \
-w c717fa22472d7b691ae5763af90e1e44244ad85a \
-t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate \
-D "/Users/mj/Desktop/apps/trace" \
LPSimpleExample-cal \
-e UIARESULTSPATH /Users/mj/Desktop/apps \
-e UIASCRIPT /Users/mj/Desktop/apps/_run_loop.js
6 out of 10 times it is working. In case of an error I get the following message:
2013-10-07 16:45:51.553 instruments[9891:1207] unable to locate CFBundleIdentifier for path: LPSimpleExample-cal
2013-10-07 16:45:51.555 instruments[9891:1207] Recording cancelled : At least one target failed to launch; aborting run
Instruments Trace Error : Error Domain=com.apple.instruments Code=1 "Error Starting Recording" UserInfo=0x7faccbef8fa0 {NSLocalizedDescription=Error Starting Recording, NSLocalizedRecoverySuggestion=At least one target failed to launch; aborting run}
Instruments Trace Error : Failed to start trace.
For me it looks that instruments has a bug here. I tried to launch the app over 100 times, in different scenarios and I can't analyze an error pattern. The device crashlog says:
Process: DTMobileIS [34956]
Path: /Developer/Library/Daemons/DTMobileIS
Identifier: DTMobileIS
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: lockbot [34938]
Date/Time: 2013-10-07 15:29:05.474 -0700
OS Version: iOS 6.1.3 (10B329)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000
Exception type EXC_BAD_ACCESS (SIGSEGV) indicates that an object which is getting accessed has been already released. A SIGSEGV is a segmentation fault, meaning you it is trying to access an invalid memory address. Reference: Exception Types in iOS crash logs
Instead of using the bundleIdentifier I also tried to specify the full app path or the full bundleIdentifier:
# with full app path
instruments \
-w c717fa22472d7b691ae5763af90e1e44244ad85a \
-t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate \
-D "/Users/mj/Desktop/apps/trace" \
/Users/mj/Desktop/apps/LPSimpleExample-cal.app \
-e UIARESULTSPATH /Users/mj/Desktop/apps \
-e UIASCRIPT /Users/mj/Desktop/apps/_run_loop.js
# with full bundleIdentifier
instruments \
-w c717fa22472d7b691ae5763af90e1e44244ad85a \
-t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate \
-D "/Users/mj/Desktop/apps/trace" \
/Users/mj/Desktop/apps/LPSimpleExample-cal.app \
-e UIARESULTSPATH /Users/mj/Desktop/apps \
-e UIASCRIPT /Users/mj/Desktop/apps/_run_loop.js
Configuration details
Instruments version: 5.0 (51166)
XCode version: 5.0 (5A1413)
Device Types: iPhone 5 - 6.1.3, iPhone 5C - 7.02, iPhone 5S - 7.0.2
Has anyone more information in which cases instruments can't launch an app on the device or when do you receive the error message unable to locate CFBundleIdentifier for path: LPSimpleExample-cal?
Are you using Calabash with Jenkins?
Has anyone more information in which cases instruments can't launch an app on the device or > when do you receive the error message unable to locate CFBundleIdentifier for path:
LPSimpleExample-cal?
I had the problem using Calabash on Jenkins and what helped me solve it was to launch instruments (calabash) in the app folder (where there is the xcodeproj.) Don't forget to copy the builded app in this folder.
please excuse me if I do not answer the question.
I had this problem when attempting to run an iOS app with instruments under the control of Xcode Server on the iDevice attached to the server host. That app, however, was never installed on the target iDevice before. I can only surmise that the error message
instruments ... unable to locate CFBundleIdentifier for path: ...
actually refers to the iDevice's file system (where that app is not present) in spite of the fact that the error message reports a path in the file system of the Xcode Server host. After I manually installed the app on the target device using my development machine once, the error message on the server host went away and instruments was working again.
My takeaway is that the error messages of Xcode Server (and/or instruments?) are just abysmally bad. Who needs enemies when you've got error messages like these?