OSX Removing app data from Xcode - 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.

Related

Verifying "Xcode" on every macOS boot

every time I start or restart my MacBook, macOS verifies Xcode.
This is not a picture from me I took it from another post but its basically the same just with "Xcode" (the app) instead of the image file.
It takes a while and for the time macOS is verifying Xcode the fan of the MacBook goes like to 100%. While its verifying I can't really use other applications because they freeze and will unfreeze when the verification is finished.
I tried to remove the quarantine xattr from the Xcode.app and recursively from all package components but there never was one set xattr: /Applications/Xcode.app/: No such xattr
I also tried to to reinstall Xcode. When booting into safe mode the same verification window appears.
This happened after I updated my mac to macOS Catalina. If you have any idea what I can try next, let me know.
Ok so apparently in my case there was something messed up with my system. I couldn't find any solution and besides the Xcode problem Reminders always wanted to access a keychain of mine. Not the login, the system or iCloud Keychain but a keychain I created myself just to store and organise some password. And when I clicked on "Deny" Reminders would ask again so I only could close this window and be able to do other things when I allow access.
Anyway after I completely reinstalled macOS (first erase the whole Macintosh HD and then reinstall Catalina) everything works fine.
So if any of you doesn't have that much of data on their Mac just a few files to back up I'd definitely try a reinstall. Took my 3-4 hours and now it works again.

Uninstall macOS app

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.

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.

Simulator in use and even restarting XCode doesn't solve it

I sometimes get a dialog in Xcode which states "Simulator in use." Restarting Xcode didn't help.
I have no Simulator Icon in the Taskbar to quit it and I have no running Simulator.
Is there any solution without rebooting?
I know some of these points to not adress your specific issue since you wrote restarting Xcode would not help you but I'll try to provide a full list of possible fixes for people who might stumble upon this one day.
Is the "Stop" Button in the left corner of Xcode still clickable ? ==> Click It
Try to reset contents & settings of iOS Simulator
Clean Build & Clean Project
Quit iOS Simulator (look at the Activity Monitor if there is still something running)
Restart Xcode
Restart Mac
This is all I can think of. For me most of the times I can resolve it by just restarting Xcode. As you wrote this does not work for you so maybe some of the other points of my list will help you.
Normally this happens when you terminate the iOS Simulator but not the debug session itself, which is why most of the times the "Stop" button in the left corner is clickable most of the times...
This dialog (and the state that triggers it) comes entirely from Xcode and not the simulator itself. This dialog will present itself if Xcode is already using the simulator from another workspace. For example, if you have three projects open at the same time and you do a Build&Run (eg: click "play") in one of them, you will get this dialog if you do a Build&Run in one of the other projects.

OSX Notification Center Icon

I'm using OSX's Notification Center APIs for the first time and can't seem to figure out how to make my app's icon to show up in the Notification badge.
The default "your app doesn't have an icon" icon keeps showing up:
Here's what I've done so far
I have created an icns file that includes 512, 256, 128, 32 & 16px versions
dragged the icon into the "App Icon" section of the target's summary
I made to sure to check the box to copy the icon into the project
the plist's "Icon file" section references the correct icon name (minus the .icns) part
Any ideas? The icon doesn't show up when I run the app thru Xcode or when I export an archive either.
I also have extracted the Sparrow.icns file from Sparrow.app and tried using that one instead of the one I made. That didn't work either.
I was able to fix this issue by incrementing the Build number in the General section for the build Target.
You can force the Notification Center to refresh all of the icons by deleting the Notification Center database file (~/Library/Application Support/NotificationCenter/SOME_UUID.db) and then killing the Notification Center process (e.g., from Activity Monitor).
Unfortunately this has the side effect of deleting your notification history, but this wasn't too much of an issue for me.
There's actually an ongoing debate on Apple's developer forums (link, link for people with access) about this. As far as I know, there's currently no real solution, but you can try the following:
Change your app's bundle ID and try it again. If you change it, clean your app, and change back, some people have reported success with seeing their icon show up.
Log in as another user. The caching Notification Center uses may be per-user, so you might be able to get the properly-iconned notifications as a different person.
The folder location has been moved for OSX 10.10+.
Following command takes to you to its new location:
$ cd `getconf DARWIN_USER_DIR`/com.apple.notificationcenter/db
and then
$ open .
Easiest way that I managed to get the icon to show up is change the Bundle Identifier in your project. This works on OSX 10.10.5 and XCode 7.2
(Once notification center picks up the change, you can change it back to your original bundle identifier if you already have a provisioning profile associated with it)
I have solved the issue by archiving my app and adding a copy to my applications folder. When the app is in Application folder, the icon is always visible even you run the app from XCode...
I tried all of the above suggestions but the only thing that worked for me on 10.14 was to delete DerivedData:
rm -rf ~/Library/Developer/Xcode/DerivedData
If anyone still having this issue, and none of the methods above worked, here is how I solved it:
open Notifications from the System Preference (easiest is to open Alfred or spotlight and type Notifications)
find your application and remove it (press backspace/delete button)
NOTE: this may remove all notifications
I am using Xcode 11.5 and I had the same problem. In my case tough, it was sufficient to clean build output, close and reopen the project. Then do a fresh build and let it run again. The icon was there afterwards.
Side note: I've placed the app icon for every size in the assets.xcassets file, except 1024 x 1024 pixels. Don't know if this is relevant or not. Hope that helps.

Resources