17

Is there a way in Xcode (4.6) to delete the application on the device before installing it ?

I need it for testing purposes and it will be easier if the application will be deleted from the device before being installed again.

giorashc
  • 13,691
  • 3
  • 35
  • 71

7 Answers7

11

Yes you can.

Get https://github.com/libimobiledevice/ideviceinstaller

Which brings you the ability to use ideviceinstaller --uninstall <app-id> in the bash environment.

Then do a script in your build configuration in xcode, such as: http://www.runscriptbuildphase.com/

Lalle
  • 676
  • 12
  • 30
  • 1
    Let me add that, the easy way to install **ideviceinstaller** is to follow the instructions in [macappstore.org/ideviceinstaller](http://macappstore.org/ideviceinstaller/) – SirEnder Mar 28 '17 at 02:34
  • Also, if when you run the `--uninstall` command, you happen to get error: **"Could not connect to lockdownd. Exiting."**, then visit: [github.com/libimobiledevice/ideviceinstaller/issues/58](https://github.com/libimobiledevice/ideviceinstaller/issues/58) – SirEnder Mar 28 '17 at 03:17
  • 1
    Note that ideviceinstaller only allows you to uninstall an application from a device. If you want to uninstall an application from a simulator you can use this command: _xcrun simctl uninstall sim-udid bundle-id_ as detailed [here](https://stackoverflow.com/questions/26394596/how-do-i-remove-app-from-ios-8-simulator-from-command-line) – Jadent Jul 25 '18 at 14:51
  • Installing `ideviceinstaller` with brew: `brew install ideviceinstaller` – Leo Jun 13 '19 at 20:27
7

The only way is to delete it manually. There's no way to have xcode delete the app from a device before running each time if that's what you were asking. Sorry, it would be a great feature, but for now, there's no way to do that. Not even on the simulator.

I think you should file a bug/feature request with apple though! That functionality would come in handy for me!

HackyStack
  • 4,887
  • 3
  • 22
  • 28
6

XCode don't offer an option for automatically removing the app from the device each time you run it but the easy way is to use the 'Device' screen to remove it a few steps:

"Window" menu > "Devices and Simulators" > select "Devices" or "Simulators" tab > select the device > select the app > "-"

Edit: This is the working link to the Apple documentation with details

Macistador
  • 854
  • 12
  • 23
  • That link is now broken. The current method of uninstalling the app you are developing from a device using XCode is: `Window -> Devices and Simulators`. Select the device. Under `INSTALLED APPS` select the `-` button.` – Dan Dec 21 '20 at 16:35
4

How about creating an Xcode build script to quit the Simulator, then delete the contents of the Simulator Applications directory. The directory is

~/Library/Application Support/iPhone Simulator/6.1/Applications/
nevan king
  • 112,709
  • 45
  • 203
  • 241
3

No, there is no way to delete app automatically.

But you can write a simple function to clean all app resources from the last run like this:

- (void)cleanUp {
    NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
    [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];

    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *context) {
        [[NSManagedObjectModel MR_defaultManagedObjectModel].entities enumerateObjectsUsingBlock:^(NSEntityDescription *entityDescription, NSUInteger idx, BOOL *stop) {
            [NSClassFromString([entityDescription managedObjectClassName]) MR_truncateAllInContext:context];
        }];
    }];
}
Krin-San
  • 316
  • 1
  • 10
  • Where should I put this? At the beginning of viewDidLoad()? – Andrej Aug 29 '15 at 13:09
  • 2
    @Andrej, call this method in your AppDelegate right after `[MagicalRecord setupCoreDataStack]` line. But notice that you must manually clean all data your app **could** write somewhere. – Krin-San Aug 31 '15 at 05:01
2

Like HackyStack, I think you have to delete the app manually. That said, you could have a debug startup method that clears the content that isn't overwritten during installation. for example, a method that removes the contents of the documents directory, keychain items associated with the app, iCloud KV info and documents, etc. It would be kind of a pain, but might get you where you want to go....

Mike M
  • 4,358
  • 1
  • 28
  • 48
2

Update 2021 (macOS 11.2.3, Xcode12.4): I have to add the mobiledevice uninstall_app com.example.bundleid to the Build Phases


Working solution With macOS 10.15.2, Xcode11.3, iOS13.3 (iPhone XS), iOS12.4.4 (iPhone 5S)

  • install: brew install mobiledevice (https://github.com/imkira/mobiledevice)
  • restart macOS
  • create/clone a Scheme
  • add this line in the Run/Pre-action: mobiledevice uninstall_app com.example.bundleid
norbDEV
  • 4,795
  • 2
  • 37
  • 28
  • This works very well if you want to delete the app from a real device. If you want to delete the app from a simulator, you can do it like this: `xcrun simctl uninstall booted com.example.bundleid` . If you are unsure what your bundle id is, you can get it during the run time with: `Bundle.main.bundleIdentifier` – Sera Nov 10 '22 at 14:50