I have an OS X app all correctly setup for using iCloud. If I archive the app and save it as an app in the applications folder and run it, it works with iCloud, but if I run it from Xcode, NSFileManager's ubiquityIdentityToken will always return nil. Anyone know what could cause this?
I've resolved this by enabling all apps in iCloud preferences->documents and data. I don't know why this helps as the app I am developing has always been iCloud enabled, but it is working now.
Related
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.
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.
When I call NSUbiquitousKeyValueStore's synchronize method after running my app directly from Xcode on macOS Sierra, it returns false and following error is printed in Console.app:
Refusing TCCAccessRequest for service kTCCServiceUbiquity from client
com.apple.dt.Xcode in background session
As far as I can tell, changed keys are not saved to iCloud. They are remembered in memory locally but lost after app re-launch.
I believe all my entitlements are set correctly (iCloud KVS enabled in Capabalities of the project, all checked). Do I need to archive & export my app in order to debug / test iCloud on macOS?
Any ideas how to fix / workaround this?
Apple DTS has confirmed that this is an issue on Apple's side and they are working on that.
Update: Problem has been solved in macOS 10.12.1
I have a pair of app, one for iOS and one for OS X, that share data through CloudKit private database and iCloud key-value store if the user chooses to, he's logged in and iCloud Data & Documents is enabled for my app and it all works fine with iCloud enabled or disabled from the beginning.
On the iOS side I can detect user choice in Settings app using ubiquityIdentityToken and URLForUbiquityContainerIdentifier("iCloud.my.default.container.for.osx") from NSFileManager to detect if user is logged in and if he enabled Data & Documents and they are nil when expected: when they are nor CloudKit nor Key-Value store works (as expected).
When changing these two settings while the app is running it is terminated so I can check for changes when it's opened again, so no problem. When I tested the same code on OS X I found that if I turn off Data & Documents in System Preferences the app is not killed but I guess it's the intended behavior, but even if I listen for iCloud availability change using
NSNotificationCenter.defaultCenter().addObserver(self, selector: "checkiCloud:", name: NSUbiquityIdentityDidChangeNotification, object: nil)
my app is not notified. If I manually check iCloud availability, i.e. by restarting the app, I found that ubiquityIdentityToken is not nil and that's correct as I am logged in iCloud, but even URLForUbiquityContainerIdentifier("iCloud.my.default.container.for.osx") is not nil and that's not what I expect.
Is this the expected behavior on OS X? If so, how can I check if iCloud is disabled and get notified when something changes? Or is this a bug (I'm testing on El Capitan)?
UPDATE: Disabling iCloud Drive all together make the notification fire and URLForUbiquityContainerIdentifier() return nil so I guess it's a bug.
UPDATE: I've filed a BugReport to Apple: #22973458
If you are building Document-based OS X app, you can use
if ([[NSFileManager defaultManager] ubiquityIdentityToken])
//iCloud Drive is enabled
to check whether or not iCloud Drive is enabled for the device.
I'm using NSUserDefaults to save some data in my application. Where can I find the file where my data is stored during development? It's a normal cocoa app (so no ios/iphone!)
Once it's deployed, it should be available in Library/Preferences/appname.plist, right? But where can I find it while I'm still working on the application?
There is no difference between "development" and "deployment". NSUserDefaults doesn't know whether you did a debug or release build. The location should be ~/Library/Preferences/yourAppIdentifier.plist no matter what.
If you are seeing a difference between development and deployment builds, maybe check the bundle identifier (CFBundleIdentifier) in your app's Info.plist.
Also: if your app is sandboxed, your prefs will end up in the sandbox: ~/Library/Containers/yourAppIdentifier/Data/Library/Preferences/yourAppIdentifier.plist. The documentation claims that the system automatically moves your old preferences file into the sandbox, if necessary, on the first launch of the sandboxed version of the app.