Reputation: 35038
Which method is better to decide which user is logged in?
let ubiquityIdentityToken = NSFileManager.defaultManager().ubiquityIdentityToken
returns a token, and client can compare wether it is the same than last time. The advantage that it returns token if device is offline too.
accountStatusWithCompletionHandler
returns only a status value, but not an ID or token about who is logged in. So in offline mode it is useless.
Am I right?
My other problem, that sometimes even user is logged in and online ubiquityIdentityToken
returns nil.
How do you retrieve user ID at launch?
Upvotes: 7
Views: 898
Reputation: 1276
If you're using CloudKit then 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 how you should get the user's record ID, which is scoped to that CloudKit container but the same for that iCloud account across devices.
In iOS 9.0, you'll also have CKAccountChangeNotification
, which will notify your app when the iCloud status on the device changes.
Upvotes: 5