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.
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/
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!
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
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/
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]; }]; }]; }
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....
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)
brew install mobiledevice
(https://github.com/imkira/mobiledevice)mobiledevice uninstall_app com.example.bundleid