How to see logs when running app in iOS simulator directly? - xcode

I want to run an app in iOS simulator directly and see the log emitted from NSLog (rather than running the app from Xcode). How can I achieve that?

Depending on the runtime version, you can use one of:
xcrun simctl spawn booted syslog -w
xcrun simctl spawn booted log stream
tail -F "$(xcrun simctl getenv booted SIMULATOR_LOG_ROOT)/system.log"
If you're on macOS Sierra, you can also select the simulated device from within Console.app to see the logs.

Related

XCode 10 shows no simulators or devices

I just reinstalled XCode 10 and now navigating to XCode -> XCode -> Open Developer Tool -> Simulator -> Hardware -> Device -> Manage Devices shows no devices or simulators:
Does anyone know what might cause that behavior, or what I can do to install a simulator version (e.g. iOS 6s)? Any help would be greatly appreciated!
So this machine had a previous version of XCode installed, and had some legacy simulators that were left over from that earlier XCode installation. Step one was to remove those simulators:
xcrun simctl delete unavailable
Then I manually created a new simulator:
xcrun simctl create duhaime-6s com.apple.CoreSimulator.SimDeviceType.iPhone-6s com.apple.CoreSimulator.SimRuntime.iOS-12-0
Those arguments are: xcrun simctl NAME DEVICE_TYPE RUNTIME. You make up the simulator name, and can select a device type and runtime from the list of options displayed if you run xcrun simctl list. After creating the simulator, you can start it:
xcrun simctl boot 4A6368C3-A94C-4D83-8AA3-9E9900ABCC74
That GUID / simulator ID will be displayed if you rerun xcrun simctl list.

Is there a command to restart the Xcode iOS simulator from command line?

I have found a command to killall simulators but does not fit my needs. I need to be able to restart a particular simulator given the udid.
I have tried shutdown and then boot the simulator using
$ xcrun simctl shutdown <udid>
$ xcrun simctl boot <udid>
$ open -a simulator
but the simulator hangs after the execution of these commands.
Xcode version: 10.3
Simulator version: iPhone XS iOS: 12.4
I'm using xcode 11.3 but this seems to work for me:
export UDID=$(xcrun simctl list devices | grep "(Booted)" | grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})")
xcrun simctl shutdown $UDID
xcrun simctl boot $UDID
Might be worth giving it an update to the latest xcode.

When launching an iOS simulator it closes straight away but still runs in the background

When I try to run a project (even a default single view app) in Xcode 10.2 (also occoured on Xcode 10.3 and beta 11 build 3) the simulator launches but then closes but Xcode still thinks it's running (looks like it is running headless). Any ideas on how I can see the simulator?
I have tried the following so far but the only time I can see the Simulator is on its first launch after that it disappears after launching.
Uninstalling and re-installing Xcode (making sure to delete all related directories and doing a system restart)
Adding and removing simulators from window -> Devices and simulators from within Xcode
Tried clearing the simulator cache xcrun simctl erase all
Tried running the following sudo killall -10 com.apple.CoreSimulator.CoreSimulatorService
Clearing Derived data ~/Library/Developer/Xcode/DerivedData/
Another thing I noticed is if I run: /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator I get the following error:
Bus error: 10
But if I run: sudo/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator the Simulator launches fine.
Thanks for any help.

How to get app version with bundle in simulator ios

I want to get the app version, code version in the simulator IOS in terminal.
I may get it in android simulator in command line by run this code:
adb shell dumpsys package com.active.dev | grep version
The question is quite old but I hope that it could help, you need to :
Get the app container using this command :
xcrun simctl get_app_container booted bundleID
Execute this command :
defaults read **The app container**/Info CFBundleVersion

Simctl install can't find Bundle Identifier in .app when installing app in simulator

When I try to install my app in the booted simulator, like this:
xcrun simctl install booted /build/iphone/build/Debug-iphonesimulator/foo.app
I get the following result:
An error was encountered processing the command (code=22):
Failed to install the requested application
The bundle identifier of the application could not be determined.
Ensure that the application's Info.plist contains a value for CFBundleIdentifier.
When I inspect the Info.plist inside the .app, the CFBundleIdentiefier is there and correct.
<key>CFBundleIdentifier</key>
<string>com.bar.foo</string>
I am using xcode 6.3.2 on Yosemite
The simulator is booted at installation time.
What am I doing wrong?
All it was, was a wrong path:
xcrun simctl install booted /build/iphone/build/Debug-iphonesimulator/foo.app
The first forward slash shouldn't be there... as simple as that:
xcrun simctl install booted build/iphone/build/Debug-iphonesimulator/foo.app

Resources