how to debug with real device using xcode tools in terminal - ios

I've already have Xcode tools installed on my mac and now I can build my iOS game project like this:
xcodebuild -scheme "Game Scheme"
and the next thing I want is to install and run the generated app (using the command above) on a real device (connect to mac).
I'm wondering if there is a command such as (I read the document about xcrun but still can not figure out how to get this done):
xcrun "my game.app" -l
to install the game on my device, run it, and print all the logs in my terminal just like Xcode did in the console.
Any advice will be appreciated, thanks :)

Doing so is a complicated process that requires reverse-engineering the MobileDevice framework interface or the underlying protocols.
Fortunately, various parties have done the work for you.
https://github.com/phonegap/ios-deploy
http://www.libimobiledevice.org/

Related

How can I build and run an iOS Swift app from the terminal?

I've recently started learning Swift and SwiftUI for iOS development and I completely understand how to run my apps for testing using XCode. You just click the play button with whatever simulator device is selected. However, I really don't like using XCode. I want to use VSCode for my development. Looking online I can find very complicated tutorials on how to build my project for release on the App store or "Ad-Hoc" from the terminal. But, I don't think this is what I need. I'm wondering if there is a way to build and run my app from the terminal on to a simulator or personal device (connected with USB)? I understand I can just have XCode open on the side and run it from there while developing from VSCode, but, my computer is kind of old and having both those apps open makes my fans go crazy.
You can follow this guide on how to build your project using xcodebuild.
Assuming you are in the directory with the .xcodeproj file, the command will look something like this:
xcodebuild -destination "platform=iOS Simulator,name=iPhone 14 Pro Max,OS=16.0" -scheme YourScheme SYMROOT="./build" build
Of course, you can choose any simulator you like. You can find a list of the simulators by doing xcrun simctl list.
The built app will be located in a folder called build/Debug-iphonesimulator, or build/Release-iphonesimulator, depending on your default configuration. The configuration can be set by the -configuration option.
Now you can launch the simulator. Here is a guide for that. Basically, you just specify the UUID of the simulator (again you can find this using xcrun simctl list), and then launch Simulator.app. Example:
xcrun simctl boot 8F9690AC-FCDE-4913-9BD2-E54B3CC9F6C1
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/
To install the built app, you also need the UUID (see also this answer)
xcrun simctl install 8F9690AC-FCDE-4913-9BD2-E54B3CC9F6C1 build/Debug-iphonesimulator/YourApp.app
Finally, you launch your app by specifying the UUID of simulator, and the bundle ID of your app (source)
xcrun simctl launch 8F9690AC-FCDE-4913-9BD2-E54B3CC9F6C1 com.mydomain.YourAppBundleId

Alternatives to full Xcode install for simulator

I've been tasked with building a demo suite of our iOS application for our sales team to run on their laptops.
I know that I can install Xcode on their machines and then create a shortcut for the simulator, but that feels really heavyweight for our sales folks.
I've used my google foo and I see that there are several choices in the windows world, but I've not seen an alternative for OS X. Does anyone have suggestions for a standalone iOS emulator on OS X?
I suggest you do the following:
Install Xcode.app on your system
Build & Run your demo app, targeting each sim device you want them to demo (or use xcrun simctl install /path/to/your/built.app)
Make a tarball of ~/Library/Developer/CoreSimulator/Devices
Untar that tarball into ~/Library/Developer/CoreSimulator/Devices on each demo machine.
Install Xcode.app on each demo machine and just place Simulator.app in the Dock.
If you're really concerned about disk space, you can delete a bunch of things inside of Xcode.app that aren't needed, but make sure you keep CoreSimulator.framework, SimulatorKit.framework, Simulator.app, simctl, and anything that has "CoreSimulator" as a parent directory.
Have you tried https://appetize.io/?
I've used a few demos in the browser and it seems like a very lightweight way to at least demo an app (although performance is suffers a little since its in a web browser).

Xcode command line install to device

I am trying to install an app from XCode onto my device from the command line. I have tried several of the "xcodebuild" command line options which do build, clean, install, etc fine. I have also searched for various solutions.
I was able to execute this command but it just builds to a folder.
xcodebuild install -scheme "My App" -destination 'platform=iOS,id=mydeviceid'
I am able to take that folder from my hard drive and sync to the physical device using iTunes so all the build steps are being completed successfully. However, it does not "run" on the device like when Build and Run are executed in XCode.
There are some 3rd party solutions but I can't believe there isn't some native xcodebuild switch to do that. Does anyone have suggestions?
Thank you
There is no native xcodebuild switch to install to a device.
You need to fallback to third-party options:
$ brew install ideviceinstaller
ios-deploy
You can try to use Apple Configurator 2 (available in the App Store) and install the cfgutil command line tool.
.
Ignore the fact that ^ says "Uninstall Automation Tools...", if you haven't installed already, it will say "Install Automation Tools...".

Running iOS app on a different Mac / simulator

I have built a demo iOS app on my Mac. My client wants to get the executable and run it on his iOS simulator on his Mac so as to give me feedbacks. I have an Apple developer account and I can deploy my app to my iPad / iPhone or distribute it via AppStore. But I don't know how to generate an iOS simulator executable for him. He only wants the iOS simulator executable. Does anyone have tried this before?
P.S. I can't really distribute it via AppStore since it is just a demo app. It is very likely rejected. Plus, I have to send it to him today so I don't think Apple can pass my app within a day.
P.P.S. I can't give him the source code unless he pays me. But it is not possible after a month.
Please help. Thanks in advance!
You need to send him the Application folder under the iPhone Simulator folder.
You can find it here:
~/Library/Application Support/iPhone Simulator/<Simulator-Version>/Applications/
Building upon this answer by #Midhun, for later versions of Xcode (Xcode 6, Xcode 7 and Xcode 8 in my research), the simulators now live here:
~/Library/Developer/CoreSimulator/Devices
I was actually trying to use an app built on Xcode 8 for iOS8 simulator and get it to run on an ios7 simulator from Xcode 6 on another Mac. I couldn't find out how to simply copy files around but I did manage to copy the Mine.app folder to the other Mac, then install it using
xcrun simctl install 6DC6323C-504C-423F-ACD6-652557B33D48 Mine.app
where you need to replace 6DC6323C-504C-423F-ACD6-652557B33D48 with your simulator device type ID (find using xcrun simctl list devices).
For running app, build on other mac machine to yours machine simulator. we require .app file for that project.
run below command in terminal
xcrun simctl install booted $LOCATION/FILENAME.app
replace $LOCATION with the path and the FILENAME should be the name.for more details check this link => https://www.webdigi.co.uk/blog/2016/how-to-transfer-your-app-to-an-ios-simulator-on-another-machine-using-app-file-and-xcrun/
iOS Run .app on another simulator
Build .app[About]
Xcode: Product -> Build
xcodebuild command[About]
//building workspace
xcodebuild -workspace "/path/to/workspace" -scheme "MyShemeName" -sdk iphonesimulator CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
Find .app
//1. Build location*. Usually it is derived data folder
//2. Xcode.
Project navigator -> project -> Products group
//3. Get it from iOS simulator
Activity Monitor -> <App Name>(not Xcode) -> Double click -> Open Files and Ports -> Find <App Name.app> path -> find and copy a file <App Name.app> by path -> save the file locally
[Build location]
Install .app
xcrun simctl install booted <app_path.app>
Or you can send just the one app you need from ~/Library/Application\ Support/iPhone\ Simulator/7.0/Applications/GUID-OF-YOUR-APP
i have used a similar tool called Simulator Bundler in a recent project with no issues,
https://github.com/landonf/simlaunch/downloads
Midhun MP answer is good but in case of solution don't work then in emergency sometimes making video and sending it to client would help. This tool provide light weight video creation.
http://www.screencast-o-matic.com/
You can resize it for your simulator.

Can I sign the iOS app with an AdHoc profile wihtout using XCode?

Preferably using Linux, Windows is also OK.
Something like openssh and zip?
If you can remotely shell into the Mac (ssh), then you should be able to build and sign your project from the command line. It may require some setup beforehand, but xcodebuild and xcrun should get you where you need to go. (This is the same kind of thing folks do to get automated continuous integration builds set up.)
Doesn't get you out of using Xcode or a Mac, but maybe gets you out of having to be physically sitting in front of that Mac to get work done.
Further reading:
Xcode “Build and Archive” from command line
xcodebuild man page
xcrun man page
I would use TeamViewer ( payed version) or other remote desktop software to connect tom office mac mini. Otherwise you will break up the signing license too, beside it is hard to configure the keychain.
It will be very hard to figure out after you have signed a build why it doesn't install at client's PC, because no error messages there.

Resources