How to Checked user Logged into iCloud in Swift?


Normally you can checked from Setting. Go to setting > iCloud and Checked, User is Logged In in iCloud or Not, But it is manually checked, But here want to check using programming, Because You are programmer (iOS Developer).



See the below Method to checked user Logged In in iCloud or Not.

func isICloudContainerAvailable()->Bool {
        if let currentToken = NSFileManager.defaultManager().ubiquityIdentityToken {

            print(currentToken)
            return true
        }
        else {
            print(currentToken)
            return false
        }
    }
Now Calling this Method in ViewDidLoad Method as below.
print(self.isICloudContainerAvailable())

Logged In iCloud : Then print True and got UbiquityIdentityToken value as : 5a988852 0we34r5t a98u34t6 weet45y3.


Not Logged In iCloudThen print False and got UbiquityIdentityToken value as : Nil

NOTE : IF You are Checking in device and login in iCloud , But you get UbiquityIdentityToken as nil ,  Then Your provisional profile in Invalidate or Expired. Download New Provisional, after you get token.

Thanks.


How to Checked user Logged into iCloud in Swift? How to Checked user Logged into iCloud in Swift? Reviewed by Kirit Modi on 09:24:00 Rating: 5

No comments:

Powered by Blogger.