zhoudu
zhoudu

Reputation: 661

Why is ubiquityIdentityToken always nil?

I am developing an iOS app that uses CloudKit. Apple's documentation says that I should use NSFileManager's ubiquityIdentityToken property to detect whether the service is available. But the property is always nil. How can I do to solve it? I am testing my app on an iPhone 5 simulator with iOS 8.2. And I have also logged into an iCloud account. I have also turned on iCloud Drive. (Someone says that turning on iCloud Drive may solve this problem, but this doesn't work for me.)

Do I need to call NSFileManager's method URLForUbiquityContainerIdentifier:? But Apple's documentation says that it is needed for document storage. It doesn't say that it is needed for CloudKit.

Upvotes: 4

Views: 1220

Answers (1)

Dave Browning
Dave Browning

Reputation: 1276

The CKContainer accountStatusWithCompletionHandler method is how you should check whether the user is logged into iCloud or not (supported since iOS 8.0). The CloudKit Quick Start shows an example of how to use it. fetchUserRecordIDWithCompletionHandler is another option that might make sense for your app.

In iOS 9.0, you'll also have CKAccountChangeNotification, which will notify your app when the iCloud status on the device changes.

Upvotes: 3

Related Questions