How to install iPhone application in iPhone Simulator - iphone

I have a mySample.app file - an iPhone application developed by xcode.
How do I run this (only mySample.app file) application using my xcode?

Please note: this answer is obsolete, the functionality was removed from iOS simulator.
I have just found that you don't need to copy the mobile application bundle to the iPhone Simulator's folder to start it on the simulator, as described in the forum. That way you need to click on the app to get it started, not confortable when you want to do testing and start the app numerous times.
There are undocumented command line parameters for the iOS Simulator, which can be used for such purposes. The one you are looking for is: -SimulateApplication
An example command line starting up YourFavouriteApp:
/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication path_to_your_app/YourFavouriteApp.app/YourFavouriteApp
This will start up your application without any installation and works with iOS Simulator 4.2 at least. You cannot reach the home menu, though.
There are other unpublished command line parameters, like switching the SDK. Happy hunting for those...

This thread discusses how to install the binary on the simulator. I've done it and it works: http://forums.macrumors.com/showthread.php?t=547557
From the thread:
Look inside your
~/Library/Application Support/iPhone Simulator/User/Applications/
directory and see what happens inside this directory when you install and run apps using XCode, and also when you delete apps using the Simulator.
You can run the Simulator by itself (without starting XCode).
If you start the Simulator, delete an app, quit the Simulator, put back copies of the files that were deleted from the support directory, and restart the Simulator, the app will reappear in the Simulator. Email those files with instructions about how to copy them into the appropriate support directory.

You can install apps in simulator from Xcode 8.2
From Xcode 8.2,You can install an app (*.app) by dragging any previously built app bundle into the simulator window.
Note: You cannot install apps from the App Store in simulation environments.

If you're looking to do this XCode 5+, I found this is the easiest method:
Install ios-sim:
npm install -g ios-sim
Then simply execute:
ios-sim launch ./mySample.app --devicetypeid com.apple.CoreSimulator.SimDeviceType.iPhone-6
In which you can switch up your device type. Simple, fast, and it actually works.

From Xcode v4.3, it is being installed as application.
The simulator is available at
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iOS\
Simulator.app/

Enter the following in the terminal:
$/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication path/to/your/file/projectname.app/projectname

I see you have a problem. Try building your app as Release and then check out your source codes build folder. It may be called Release-iphonesimulator. Inside here will be the app. Then go to (home folder)/Library/Application Support/iPhone Simulator (if you can't find it, try pressing Command - J and choosing arrange by name). Go to an OS that has apps in it in the iPhone sim, like 4.1. In that folder there should be an Applications folder. Open that, and there should be folders with random lettering. Pick any one, and replace it with the app you have. Make sure to delete anything in the little folders!
If it doesn't work, then I'm dumbfounded.

Select the platform to be iPhone Simulator then click Build and Go. If it builds correctly then it will launch the simulator and run. If it does not build ok then it will indicate errors at the bottom of the window on the right hand side.
If you only have the app file then you would need to manually install that into the simulator. The simulator was not designed to be used this way, but I'm sure it would be possible, even if it was incredibly difficult.
If you have the source code (.proj .m .h etc) files then it should be a simple case of build and go.

This worked for me on iOS 5.0 simulator.
Run the app on the simulator.
Go to the path where you can see something like this:
/Users/arshad/Library/Application\ Support/iPhone\ Simulator/5.0/Applications/34BC3FDC-7398-42D4-9114-D5FEFC737512/…
Copy all the package contents including the app, lib, temp and Documents.
Clear all the applications installed on the simulator so that it is easier to see what is happening.
Run a pre-existing app you have on your simulator.
Look for the same package content for that application as in step 3 and delete all.
Paste the package contents that you have previously copied.
Close the simulator and start it again. The new app icon of the intended app will replace the old one.

The Short Answer
For those who can't wait, the following command installs an iOS app bundle to the specified simulator.
xcrun simctl install 2A3F00EE-F412-4999-8109-ED3D4E70D266 ./YOURAPP.app
The Long Version
The full story is in this Quip doc.
xcrun
Apple has a command-line tool called xcrun that looks for the named command-line tool in the active developer directory and runs it. We will use xcrun simctl in this article.
Active Developer Directory
A user of macOS could install more than one version of Xcode and use the xcode-select command to choose which one to use. Each Xcode bundle that has been installed has a folder called Developer. The following command shows the developer directory that is currently being used.
$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
List Simulator Types
The xcrun simctl list devicetypes command shows all of the simulator types that are installed on the macOS system. Think of simulators as virtual machines (VMs). Each type is like a VM specification.
$ xcrun simctl list devicetypes
== Device Types ==
iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
...
iPhone 12 (com.apple.CoreSimulator.SimDeviceType.iPhone-12)
...
Create a Simulator
The following command creates a simulator named yi-iphone12-sim that is of the type com.apple.CoreSimulator.SimDeviceType.iPhone-12, as shown above.
$ xcrun simctl create yi-phone12-sim com.apple.CoreSimulator.SimDeviceType.iPhone-12
No runtime specified, using 'iOS 16.2 (16.2 - 20C52) - com.apple.CoreSimulator.SimRuntime.iOS-16-2'
2A3F00EE-F412-4999-8109-ED3D4E70D266
It prints the ID of the new simulator.
List Created Simulators
The following commands lists simulators.
$ xcrun simctl list devices
== Devices ==
-- iOS 16.2 --
yi-phone12-sim (2A3F00EE-F412-4999-8109-ED3D4E70D266) (Shutdown)
We can see that it lists the simulator yi-iphone12-sim, and its status is Shutdown.
Boot a Simulator
The following command boots the simulator yi-iphone12-sim.
$ xcrun simctl boot 2A3F00EE-F412-4999-8109-ED3D4E70D266
Please note that we can't use the name yi-iphone12-sim. Instead, we'll use the ID.
After the home screen is shown on the simulator window, the xcrun simctl list devices command shows that the simulator is Booted.
$ xcrun simctl list devices
== Devices ==
-- iOS 16.2 --
yi-phone12-sim (2A3F00EE-F412-4999-8109-ED3D4E70D266) (Booted)
Install an App to the Simulator
I checked out this project at https://github.com/sheldonth/ios-cmake/tree/master and built it with CMake. The result is an iOS bundle called ./build.sim64/Release-iphonesimulator/YOURAPP.app.
This app will be installed on the simulator with the following command.
xcrun simctl install 2A3F00EE-F412-4999-8109-ED3D4E70D266 build.sim64/Release-iphonesimulator/YOURAPP.app

Related

Jailbreak development using xcode

I have been looking around for learning how xcode can be used for jailbreak development.
I have Lion and jailbroken iPhone3G and xcode4.6 which doesnt support iPhone3G.
I have installed ldid but have no idea how to use it.
I have to make launch daemons, too, and attach them with my application. I have followed this tutorial for making a daemon but i got stuck in the setup for creating an open tool chain template in xcode. I followed every step but my xcode is not showing any template for open tool chain. Is it really required to have open tool chain template?
You're right. Xcode 4.6 doesn't support the iPhone 3G. Can you install an older version of Xcode? For example, Xcode 4.4 still supports the 3G.
Login to the Apple Developer Portal and download old versions here
You can choose to install the old version of Xcode in a different folder, so that it doesn't overwrite the new version (for example, install to /Developer-old/ or something).
Once you install the old Xcode version, you can navigate to the installation directory and look for the directory named:
iPhoneOS5.0.sdk
(or probably iPhoneOS5.1.sdk would work, too). Then, copy that entire folder into the new Xcode 4.6 installation directory. For example:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
Afterwards, you should see this:
iPhoneOS5.0.sdk
iPhoneOS6.1.sdk
With the 5.0 SDK installed, you can now build apps for the iPhone 3G, using Xcode 4.6. You can also now uninstall Xcode 4.4 if you want. See more about this in this other question. The key is that you will be building your app for armv6 (only). Armv6 is the iPhone 3G's processor.
The second step is to turn off code-signing within Xcode. In your project settings, you set the provisioning profile to Don't Code Sign. You must modify an Xcode configuration file to allow you to do this.
Now you build the app in Xcode. When you're done, navigate to the directory on your Mac where the app has been built (where the MyAppName.app/ folder is). Then, you use ldid to fake code sign the app executable:
ldid -S MyAppName.app/MyAppName
Now, your app has a fake code signature that will allow it to run on a jailbroken phone.
Then, you use ssh, or scp, or something else to transfer it to your phone, where it should be installed under /Applications/.
You already have the best link on building iOS Launch Daemons. I'd stick with that tutorial. No, I don't have any open toolchain template in Xcode, either. I just use Chris' tutorial to see how to build a non-graphical daemon main program (not a UIApplication), copy it to my MyAppName.app folder, and create a com.mycompany.mydaemon.plist file that defines the Launch Daemon.
Once the plist is installed in /System/Library/LaunchDaemons/ on the phone, you can start it, without having to reboot the phone, with:
launchctl load -w /System/Library/LaunchDaemons/com.mycompany.mydaemon.plist
at the command line (on the phone). Or, just reboot the phone, and the daemon will start automatically.
Although I learned to do this before it was available, you can now look at iOSOpenDev if you'd like a more polished way of doing some of this stuff.
Yes. Xcode can be used for developing jailbreak-type projects. Use iOSOpenDev to set up Xcode and iOS SDK to allow jailbreak-type development.
iOSOpenDev comes with a set of templates, signs (with ldid) targets and creates Debian packages (packages are submitted to repos like ModMyI and BigBoss) during its build phase, in addition to installing packages directly to an iDevice with Cmd-Shift-I (build for profiling shortcut) for immediate testing, among other useful features for using Xcode to develop jailbreak-type projects.

Jailcoder how to

I just tried to get my own app on my iPhone without a developer account. The following are steps I did:
I patched Xcode and my project (Currency.xcodeproj) with JailCoder
I want to build the project with "iOS device" in Xcode. But I got a error message like "no device found". So I ran it in the emulator and I got the currency.app-file in /Users/Dogan/Library/Developer/Xcode/DerivedData/Currency-gjxrulouxbmjslbzslsplyehgfgm/Build/Products/Debug-iphonesimulator
SSH to iPhone in /var/mobile/Applications
Creating a new folder named FADE9826-4878-4458-B5BE-90AD4EB60FDF (I have to take a valid UDID. Have I use to specific tools to create a UDID? I have the UDID from an other example). I also created a directory in this folder with the name "Documents".
chown -R mobile FADE9826-4878-4458-B5BE-90AD4EB60FDF
scp -r Currency.app root#IP-ADRESS-OF-IPHONE:/var/mobile/Applications/FADE9826-4878-4458-B5BE-90AD4EB60FDF/
Restarting Springboard in SSH with "killall SpringBoard"
I got the app, but it doesn't work. Every time on click, it crashes and kicks me to the home screen. Had I missed something?
You missed that simulator builds don't work on iPhones, because they are built for the wrong CPU type. Simulator builds are Intel x86 apps, and the iPhone has an ARM CPU.
There might be other problems (I don't know how jailcoder works) but there's no way you're getting the simulator build running on the phone.
After downloading Jailcoder and going through the guided patch of Xcode and then patching your project, if your device is plugged into your computer, select the target type (where you can select simulator, iOS Device, etc.) and there should be a listing of your device's name.

Run iPhone/iPad Simulator for Continuous Integration

I am attempting to run the iOS simulator from the command line. I have found the location where the iPhone Simulator can be run from. My question is whether or not it can receive parameters to specify which device should be launched and what app it should run.
$ ./Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone\ Simulator
Does anyone know if there are tricks to this. Knowing more about this would really help with our Continuous Integration process.
We now use WaxSim to automate our iOS applications during CI Builds
Use the -SimulateApplication argument to run your executable in the simulator (executable inside the .app bundle)
(you could also compile the project from the command-line like this:)
xcodebuild -project Test.xcodeproj -arch i386 -sdk iphonesimulator
Then for example:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication Test.app/Test
or
./Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication Test.app/Test
To launch a specific device you can do:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateDevice "iPhone Retina (3.5-inch)"
Try this in your shell for Xcode 6
osascript -e 'activate application "iOS Simulator"'
For Xcode 7
osascript -e 'activate application "Simulator"'
If you want to open Simulator with specific app installed then you can use some of the ready utility to launch simulator. This way it is easy to install the app and run on the simulator. This are the command line utilities that can be run from Terminal Window.
iPhoneSim
ios-sim
Other are same as above two.
And main thing is all uses same approach to open simulator. (see the project for more details)
Other way (not recommended by me) use script file to run from command.
You can use xcrun simctl to list available simulators, launch applications, etc. This tool is present in both Xcode 7 and Xcode 8. If you don't give it a command it will print command line help.
xcrun simctl launch <UUID> <bundle id of app> will start the application.

How do I automatically run my iphone app after building it?

I'm using google unit testing code.
I'm building it quite nicely with xcodebuild on the command line. Now I want to run it (preferably on attached Device but simulator would also work) and catch all the feedback from the tests.
But I can't find out how to run it. Any ideas?
Jeff Haynie's iphonesim project on Github looks like it could work. I had trouble building 27812bb4b (make failed on a warning in nsprintf.m), but that may just be me using a pre-release OS and SDK. See also this related question.
If you followed the instructions from the Google page (creating the target, adding the test files to the target) and you have an iPhone SDK certificate (you need it to upload apps to the device) you can just change the Active SDK to your device (upper left corner combo in XCode)
If you don't have a certificate, you need to apply to the SDK program.
The only iPhone simulator and debugger I'm aware of comes with the iPhone SDK. In order to use the iPhone SDK you need to have an Intel-based mac with OS 10.5 Leopard installed, in which case you might as well be programming/compiling in XCode instead of using the command line.
There has to be some misunderstanding here. What exactly do you want to run from the command line? The test suite? If so, the test suite should be a separate target, so that all you have to do is build it, for example like this:
xcodebuild -target UnitTests -sdk iphonesimulator2.2.1 -configuration Debug
If you have the testing target configured correctly, it will run the RunIPhoneUnitTest.sh shipped with the Google Toolbox and the script will run all your tests.

How can I deploy an app to my iPhone from the command line?

I can already build an app with a distribution profile via the command line
xcodebuild -configuration Distribution -sdk iphoneos3.0 clean build
However, I'd like to go one step further and install the app to the connected iPhone and execute it ( as if I'd pressed Build and Run in XCode ).
The final command listed in the build commands window ( cmd+shift+B ) is CodeSign, which as far as I know just signs the code and nothing else. So I'm not sure what command ( if any is available ) I can run from the command line to install and run the app on the iPhone.
I'm running the official SDK, not a jailbroken phone.
If you have a post build script you should be able to install it and run it using a script. If you're jailbroken you should be able to use SCP and then execute it directly.
There may be an AppleScript or automator way of solving the problem as well.
I've written a blog entry on how to install apps on a connected iPad / iPhone without using Xcode or iTunes. This method does NOT require JailBreak - any iOS device will work. Only works on the Mac though.
This method allows you to run a Terminal command to install an iPA file.
http://pervasivecode.blogspot.co.uk/2012/06/install-ios-app-ipa-file-without-xcode.html