UbiquityIdentityToken vs CKContainer accountStatusWithCompletionHandler

Which method is better to decide which user is logged in?

let ubiquityIdentityToken = NSFileManager.defaultManager().ubiquityIdentityToken 

returns a token, and the client can compare it, as well as last time. The advantage is that it returns a token if the device is also disconnected.

accountStatusWithCompletionHandler returns only the status value, but not the identifier or token about who is logged in. Therefore, offline it is useless.

I'm right?

My other problem is that sometimes even the user logs in, and online ubiquityIdentityToken returns nil.

How to get user id at startup?

+4
source share
1 answer

If you use CloudKit then the CKContainer accountStatusWithCompletionHandler method is how you should check if a user is registered in iCloud or not (supported with iOS 8.0). CloudKit Quick Start shows an example of how to use it.

fetchUserRecordIDWithCompletionHandler is how you should get the user record ID that is bound to this CloudKit container but the same for this device iCloud account.

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

+3
source

All Articles