Detect iCloud availability change on OS X - xcode

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.

Related

Change iOS simulator iCloud account

I am trying to debug a CloudKit issue which means I need to see the data being saved to iCloud in the CloudKit dashboard. I have two iCloud accounts, one which is for my personal email address, and the other for my work address and which I use for iOS development. The iOS simulator seemed to pick up the iCloud account from the Mac, so the entries being saved by the app were not visible in the CloudKit dashboard. I tried logging the Mac out of my personal iCloud account, logging in to the work account, restarting the computer, resetting the content and settings of the simulator, cleaning and rebuilding the app, but it still shows all of the data I entered while on the personal iCloud account. How can I configure Xcode or the simulator to log in to a different iCloud account?
FFS... I'm an idiot. I was using the public database 😖

Allow App Data to be downloaded to iCloud (Nativescript)

My Nativescript iOS app saves some user created data using the nativescript-localstorage plugin. I want to be sure that users have a place to back-up this data.
The most straightforward option seems to be that they can include the app's data in an icloud backup (ie, icloud -> icloud Drive -> then allow the app to be backed up in the drive).
When I have used "$ tns run ios" and run the app locally on my phone, the app properly runs on my phone, but it does not appear as an option for backing up to icloud. On the icloud backup screen where apps are listed that you can choose to backup, my app does not appear.
This might be because it is just a local build, and only full releases (apps received from the app store) can be included in icloud backups, but I have not seen this confirmed anywhere.
Do I need to do anything to enable my app to be available for icloud backup?
I have figured out the key piece I was missing--that there are two different types of iCloud uses:
(i) the system-wide iCloud backup that happens automatically if the user turns it on (app developer does not need to take special action) and (ii) the iCloud as a cloud storage solution for certain data that you as the programmer need to configure.
For iCloud with CloudKit to show up as a specific feature of your app, this requires (ii)--and further configuration than just enabling it.
Further detail in my answer here.

Mac OSX Core Data App - Cannot turn on iCloud Capability

I have a published Mac app which uses Core Data and I am in the beginning stages of implementing iCloud (Documents) to sync data between devices (using Ensembles). When I attempt to turn on iCloud the app does not run. It builds successfully and then says it has finished running. This message appears in the Console:
Message from debugger: unable to attach
If I turn off the iCloud capability it will run successfully with no issues.
I am logged into iCloud, and there are no issues shown in the setup. Any ideas as to why I cannot use the iCloud capability? The same issue occurs if I try to activate Push Notifications (even with iCloud Off).
iCloud Settings 1
iCloud Settings 2

NSFileManager ubiquityIdentityToken returning nil

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.

UIDocumentPickerViewController & iCloud entitlement in IOS 8

I have a document based app in App Store. Now I am trying to use UIDocumentPickerViewController in my app to share the file from my app UIDocumentProviderExtension supported apps.
Previously I have used UIDocumentInteractionController to transfer files between apps. The problem is when I used UIDocumentPickerViewController, I got the error "iCloud entitlement missing" in app.
According to the Apple document, I need to add the iCloud entitlement if my app supports the iCloud storage, but it's not a requirement for my app. So, I want to understand what is the need of iCloud entitlement for presenting UIDocumentPickerViewController?
the UIDocumentPickerViewController allows your app to access the shared iCloud documents even if your app does not support iCloud document storage itself. This is the default behavior of the UIDocumentPickerViewController.
So if you want to use the UIDocumentPickerViewController you have to add iCloud entitlement to your App ID.
If not, you might want to create an DocumentProviderExtension in your app. Then you don't need to add the iCloud entitlement to your app id and your users can access your documents from within their preferred app (which has a UIDocumentPickerViewController).

Resources