Uninstall macOS app - xcode

I am testing my macOS app, and I need to uninstall it to check some special features. For iOS apps this is very simple, I simple remove the app from the simulator and then I reinstall it. How can I do the same thing for macOS?
I've already tried to delete the app from /Users/myuser/Library/Developer/Xcode/DerivedData/Build/Products/Debug/myapp.app
But that doesn't work. If I run my project again, all previous settings and saves are kept.
How can I completely remove an app made in Xcode for macOS development?
The topic: Delete app from OSX simulator in Xcode didn't help me.

This command will delete whatever's in the UserDefaults database for your app:
defaults delete com.mywebsite.myapp
Replace com.mywebsite.myapp with the bundle ID of your application.
If you have items other than just UserDefaults settings, they'll appear in the home/Library/Containers folder in a folder named after your app bundle (assuming your app is sandboxed; otherwise check home/Library/Application Support). You'll find the plist file for your UserDefaults in here as well, although deleting that using the Finder isn't reliable, since the system sometimes caches the plists in memory, so the defaults command is still the best way to clear that.

There are many apps that allow you to thoroughly uninstall apps, for example AppCleaner. However I'd try to use the clean build folder option within Xcode first.

Related

How to delete an application in sandboxed App?

I am trying to delete an application in the /Applications folder on macOS High Sierra (I don't hink the exact OS really matters).
But I simply can not figure out, how to do so from a sandboxed app. In the Mac App Store there are a couple (in fact a lot) of apps that can do that.
When an app is selected, a prompt is shown where I can type in my password.
First I tried creating a helper utility and then calling SMJobBless. But after failing I noticed that this is not possible in a sandboxed app (kinda makes sense because you could completely bypass the sandbox?).
Then I tried to write an AppleScript. This really works fine, the prompt is shown and the file is either deleted or moved to the trash.
I had to add an entitlement:
com.apple.security.temporary-exception.apple-events
I have added co.apple.finder as a child node and like I said everything works fine. Unfortunately, this entitlement is not allowed in the Mac App Store (again, this makes sense).
Now my question is...how can I move a file to the trash (I do not need to delete it myself, it would be okay if the user had to empty the trash manually).
How do all those other apps do it?
Only way I can think of would be to open an NSOpenPanel, and get the user to select the application you want to delete. Not too many MAS-approved ways to poke through the sandbox beyond that.

After changing Document Parameters, NSCocoaErrorDomain 256 opening *new* docs

For the next version of a NSDocument-based app, I am revising the document parameters, that is, the values in Info.plist > CFBundleDocumentTypes and UTExportedTypeDeclarations. Specifically, I am changing from a flat NSPersistentDocument to a document package (with the help of BSManagedDocument).
The revised app can create new documents, but they appear in Finder with a generic icon, and when I close such a new document and try to re-open it, -[NSDocumentController openDocumentWithContentsOfURL:display:completionHandler:]fails, creating an error in NSCocoaErrorDomain with code 256, description “newDoc.myExtension” could not be handled because MyApp cannot open files of this type, and failure reason MyApp cannot open files of this type.
I understand that there are several significant parameters CFBundleDocumentTypes and UTExportedTypeDeclarations, and these must all be correct or you get this error. In this case, they are correct. I've confirmed this by comparing the Info.plist in my built product with the Info.plist of a different but similar app that works.
I've also tried calling LSRegisterURL() with inUpdate = true from main(), but that did not help.
What might be wrong? I'm running in macOS 10.12.6, building with macOS 10.13 SDK and Xcode 9.
Apparently the problem is in updating the Launch Services database. I copied the new application, with the revised Info.plist, into /Applications, replacing an old version, then launched this copy once. After these two steps, document icons are now correct when I reopened a Finder window, and upon relaunching my new app, it can now reopen its own new documents without error.
UPDATE: Today (macOS 10.13 Beta 8) I had the same problem, but installing the corrected app into /Applications did not work. However, this time, rebuilding the Launch Services database by running the following command in Terminal, and then relaunching my app, did work:
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain u -domain s -domain l -v
A side effect of the above is that some apps will have generic icons in the dock and cmd-tab application switcher until relaunched.
I think that either Launch Services much prefers apps in /Applications over apps in Xcode's DerivedData folder, even if the latter is the only one currently running, or running apps from Xcode's DerivedData do not register at all, or both.
It seems from the documentation that calling LSRegisterURL() should have had the same effect, but apparently not.

OSX Removing app data from Xcode

New to OS X development and have tried removing ~/Library/Developer/Xcode/DerivedData from my system, Product>Clean but still wouldn't wipe the data. I know its much simpler in iOS simulator. Any advise on removing OS X app data completely so that it runs like as if its the first time?
Unlike iOS apps, macOS apps don't delete all of their data when uninstalled.
Assuming the data you are referring to is stored in the UserDefaults, this is the solution I found to test the app first launch.
Quit Xcode
Remove the DerivedData folder
Delete the UserDefaults plist file. Depending on your app's configuration it will be in one of these locations (more info in this answer):
Sandboxed apps:
~/Library/Containers/com.example.myapp/Data/Library/Preferences/com.example.myapp.plist
~/Library/Containers/com.example.myapp/Data/Library/SyncedPreferences/com.example.myapp.plist
Non sandboxed apps:
~/Libraryf/Preferences/com.example.myapp.plist
~/Library/SyncedPreferences/com.example.myapp.plist
Relaunch the app from Xcode
If the only thing you need to test is a flow based on a "first launch flag" (a Bool in the UserDefaults that is set to true after first launch), you can reset that one along with this command:
defaults write com.example.myapp "settingName" "0"
You'll still have to quit Xcode, delete the DerivedData, and re-open Xcode for the change to take place.
Note that sometimes this doesn't work on the first try. I'm not sure why but I'm guessing Xcode does some state tracking inside that gets in the way. In my experiments, I had to restart Xcode a few times before getting it to read the updated defaults.
Oh just open up the Simulator and click (and hold) on the app icon. Then it'll shake and you click the 'x' in the corner to delete the app and its data.

Updating XCODE using different apple account

I have MAC OS 10.7.3. xcode 4.3.1 installed using different apple id as my macbook pro was used previously by my friend. Now when i try to upgrade Xcode to 4.3.2 it asking credentials for my friends account. Unfortunately App store clearly says you can upgrade an app using the account which was used to install the app.
How can i upgrade Xcode using my credentials?
Thanks in advance.
I am sure you would have solved this by now but just posting the solution here that worked for me..
Open Finder and navigate to Applications,
Ctrl+Click the application and choose "Show Package Contents" (Xcode in this case),
Expand the Contents directory and click the _MASReceipt directory to select it, Type Command+Delete to
delete the directory permanently---you will be prompted for your
credentials since this is a protected file.
Quit and restart
AppStore, then find the application. You can update with your new id now without deleting the old version of the app
Hope this helps someone coz it took me a while to figure out !!
Unfortunately had to answer my own question,
Simple Answer: NO, You cannot update xcode installed from another account.
Solution is to delete the existing installation and re-installing from new account.
To delete the existing installation, you need to delete it from Launch pad. You can do this by locating xcode icon in launch pad, long click on the icon till it starts dancing. Then delete it and wait for a while till the xcode.app is deleted from /Application. If you manually delete xcode.app from /Application, App store will continue to think its installed and will not allow you to reinstall in future.
Above solution is assuming you have installed xcode from the mac app store, usually versions later than 4.2. For earlier versions, just deleting /Application/xcode folder should work.
The solution is found:
I had this bug, it's related to Spotlight. The App Store used Spotlight in some way. My fix was to add the entire HD to the "Privacy" tab in the Spotlight System prefs pane, close the prefs and wait 30 seconds, re-open and remove your HD from the Privacy tab. Spolight begins reindexing. Re-opened the App Store and problem was fixed! Posting this here for others who might search later on. Also filed a bug report with Apple.
Source: https://discussions.apple.com/thread/2806858?start=0&tstart=0

Sharing iPhone Apps for the Simulator

iPhone Apps built for the simulator are stored here:
/Users/<username>/Library/Application Support/iPhone Simulator/User/Applications
Is it possible to copy the <GUID>.sb and <GUID> directory and install them on a different computer (with Development tools installed)?
This would be very useful for testing/demoing with out having to buy iPhones for all the managers and external clients.
I found a way that requires just a little more setup, but is much easier for non-developers:
Instructions for your users/testers:
Install Xcode following Apple's instructions
Double-click the attached application - the iPhone simulator will launch, install the app and start it automatically.
How to set it up:
Download and unzip (to a folder on your desktop or wherever) 'Simulator Bundler' from: http://github.com/landonf/simlaunch/downloads
Set your XCode build target to the required Simulator configuration (iPad/iPhone/which iOS version)
Do a 'Build and archive'
Find it: select 'Archived applications' in the Organizer, right click the relevant build, select "Reveal archived application in Finder"
Drag the application (yourAppName, no extension) onto the Simulator Bundler app
Done. This will create a self-contained Mac OS X yourAppDisplayName.app file in the same folder (with your app's icon as the icon) that you can stick up on an FTP server or email to your users/testers.
--
I think it's much neater/slicker than having to explain where to copy files, how to launch the simulator and so on.. And if anything gets messed up they can just uninstall via the familiar tap-and-hold + (x) gesture in the simulator UI, then double-click the app you sent them again.
You can also produce several of these packages changing the bundle identifier between builds, allowing them to be installed side by side in your testers' simulators; say for getting some user feedback on different UI designs, or configure one for Production and one for Staging/QA servers, so your content editors can check their changes before they go live or whatever..
The ability to reinstall the app from a desktop icon is also very convenient for localisation testing: launch the simulator, uninstall the app if present, set the required region format and language, double click the icon on your desktop, test; repeat for each required locale. (guarantees a fresh install each time, I've found that switching language with the app installed can result in all sorts of strange behaviour)
Yes, if you send those files to another person, and they put them into that directory, they can test the applications in the iPhone Simulator as well :)

Resources