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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With