65

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?

Greg
  • 316,276
  • 54
  • 369
  • 333

10 Answers10

60

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...

racs
  • 3,974
  • 2
  • 23
  • 26
  • 1
    Unfortunately, this solution has its limitations: you cannot configure the application, and the preadjusted settings won't affect the run, doesn't matter whether you specified the exact preinstalled application for the simulation or not. The possible command line arguments, what I have found so far: SimulateDevice, SimulateRestart, SessionOnLaunch, currentSDKRoot - there might be others, though. – racs Feb 08 '11 at 20:48
  • 4
    `strings /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator` gives the follow nearby `SimulateApplication`: * LocationLongitude * LocationLatitude * LocationMode * StayInFront * windowOrientation * SessionOnLaunch * SimulateRestart * MobileSafari * Safari * SimulateDevice * SimulateApplication * LocationScenario – sj26 Feb 08 '12 at 06:46
  • 1
    It this method still working for Xcode 4.3 and iOS 5? I encountered this problem using it: https://skitch.com/an00na/8dj8r/simulator. – an0 Feb 21 '12 at 01:29
  • 2
    I still get it to work with 4.3.1. Although I did get this error when I used the path to the .app bundle instead of the executable within the bundle (i.e. foo.app/foo ). – gaige Mar 15 '12 at 12:32
  • 1
    This doesn't work on my MacOS 10.6.8. The myFavoriteApp.app/myFavoriteApp (Flash compiled) just crashes at launch. – Paolo Stefan May 22 '12 at 06:02
  • 7
    Very nice @sj26. By trial and error I've determined that (for the 5.1 simulator) "SimulateDevice" takes the following parameters: "iPhone" "iPhone (Retina)" "iPad" "iPad (Retina)" – cheshirekow Jul 05 '12 at 17:56
  • 1
    @cheshirekow This is a really helpful piece of info, I hope it finds it's way out of being buried in a comment. – rooftop Jul 19 '12 at 19:40
  • 1
    how to find that path as versions pass? – sites Apr 19 '13 at 21:36
  • 4
    The iOS 7 SDK no longer seems to take the -SimulateApplication parameter. Any ideas how to do this in iOS 7? – Dale Emery Sep 26 '13 at 23:28
  • 9
    I am afraid this function was removed from the simulator. Some other parameters are still available, like the SimulateDevice and SimulatorWindowCenterX - SimulatorWindowCenterY, but I couldn't find any sign of a string that refers to launching an application in any direct or indirect way. However, I discovered that any string specified as parameter in the command line will be opened in Safari on a path relative to the simulator's Applications folder. I am not sure how useful is that (maybe it is a documented feature). – racs Oct 07 '13 at 01:09
  • 1
    When i try to run my app it gives following error -bash: /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator: No such file or directory Can you please tell what wrong is happening? – Rahul Mathur Jul 11 '14 at 06:06
  • 1
    Maybe you need to wrap the arguments into quoting marks because of the spaces. – racs Jul 23 '14 at 04:15
  • 1
    @RahulMathur works for me: `/Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app/Contents/MacOS/iOS\ Simulator` – ptim Nov 21 '14 at 01:07
  • 1
    Appears this function was removed from the simulator. Does not work on current version. – Brian Knoblauch Jul 29 '16 at 18:06
  • 2
    Its possible from Xcode 8.2. http://stackoverflow.com/a/41671233/1522584 – Abhijith Jan 16 '17 at 07:17
12

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.

Abhijith
  • 3,094
  • 1
  • 33
  • 36
11

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.

ptim
  • 14,902
  • 10
  • 83
  • 103
ThomasW
  • 16,981
  • 4
  • 79
  • 106
9

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.

Jeff Huijsmans
  • 1,388
  • 1
  • 14
  • 35
Vetsin
  • 2,245
  • 1
  • 20
  • 24
  • 2
    According to [this](https://github.com/phonegap/ios-sim/issues/72#issuecomment-37317614) comment, `brew` isn't supported anymore. Recommended way is now `npm install -g ios-sim`. – Jeff Huijsmans Nov 08 '16 at 17:10
7

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/

Community
  • 1
  • 1
Arun
  • 336
  • 5
  • 14
  • 3
    On my system, with Xcode 4.3, it's in `/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator` – cheshirekow Jul 05 '12 at 17:57
4

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
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Yos Ra
  • 117
  • 1
  • 7
  • Sadly this no longer works (at least as of Xcode 5.0, possibly earlier) – Perry Mar 14 '14 at 01:04
  • @Perry, is there any alternatives? – RameshVel Apr 08 '14 at 09:51
  • @RameshVel I recently discovered that the old iphonesim project which provided a command line interface to the XCode Simulator has an active fork at https://github.com/phonegap/ios-sim It works well within the limitations imposed by Apple. – Perry Apr 10 '14 at 20:19
  • @Perry, yep i am using ios-sim now. it works fine now. thanks – RameshVel Apr 11 '14 at 10:39
2

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.

1

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.

Xetius
  • 44,755
  • 24
  • 88
  • 123
  • It builds fine for me and gives me the error "Failed to launch simulated application: Unknown error.". It starts the simulator in iPad mode with a blank screen. When I switch to home screen, it doesn't show my app. – Albert Jul 25 '10 at 18:09
0

This worked for me on iOS 5.0 simulator.

  1. Run the app on the simulator.

  2. 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/…
    
  3. Copy all the package contents including the app, lib, temp and Documents.

  4. Clear all the applications installed on the simulator so that it is easier to see what is happening.

  5. Run a pre-existing app you have on your simulator.

  6. Look for the same package content for that application as in step 3 and delete all.

  7. Paste the package contents that you have previously copied.

  8. Close the simulator and start it again. The new app icon of the intended app will replace the old one.

grg
  • 5,023
  • 3
  • 34
  • 50
Arshad Parwez
  • 1,563
  • 2
  • 19
  • 29
0

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
cxwangyi
  • 653
  • 1
  • 8
  • 15