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
Related
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
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"
I am working on a shell script that builds and install our xcodeproj directly to the first found and connected iDevice. This is the script
#!/bin/bash
cd ../../cordova/platforms/ios
deviceName=$(ideviceinfo | grep -i DeviceName)
deviceName=${deviceName//DeviceName: /} #This is the device name you set in Settings->General->Info->Name on your iDevice
deviceUdid=$(system_profiler SPUSBDataType | sed -n -e '/iPad/,/Serial/p' -e '/iPhone/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2}')
if [ -n "deviceUdid" ]; then
echo 'Found device "'${deviceName}'" with UUID "'${deviceUdid}'", process...'
xcodeProject=$(ls | grep -i *.xcodeproj)
if [ -n "$xcodeProject" ]; then
echo "Is xCode project dir, start building..."
################### Not working command ###################
eval "xcodebuild -scheme AppScheme -destination 'platform=iOS,id=$deviceUdid' install" #This line is not really working
################### Not working command ################
else
echo "Directory is not an xCode project directory!"
fi
else
echo 'It looks like there is no iDevice connected!'
fi
Everything works, except installing it on my iPhone. I get the correct device name, it looks like as if it finds the device, but I don't see the app on my iPhone. The strange thing is, that everything works well if I install it from xCode.
Does anyone know how to fix this issue?
I use this following commands to build and run my Application in Simulator:
xcodebuild -sdk iphonesimulator8.4 -arch i386 -workspace MyApp.xcworkspace -scheme MyApp install DSTROOT=~/MyApp
xcrun instruments -w "iPhone 5s (8.4 Simulator)"
xcrun simctl install booted ~/MyApp/Applications/MyApp.app
if you want to run in another Simulator try see available simulators with:
xcrun instruments -s
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.