How to detect if iCloud account on a device changed?

后端 未结 1 1134
無奈伤痛
無奈伤痛 2021-02-20 08:40

How to detect if iCloud account being used on a device changed?

A user signs out from Settings > iCloud and another user signs in his/her account.

1条回答
  •  日久生厌
    2021-02-20 08:49

    Just add an observer for the notification with name NSUbiquityIdentityDidChangeNotification

    [[NSNotificationCenter defaultCenter]
        addObserver: self
           selector: @selector (iCloudAccountAvailabilityChanged:)
               name: NSUbiquityIdentityDidChangeNotification
             object: nil];
    

    If a user signs out of iCloud, such as by turning off Documents & Data in Settings, the ubiquityIdentityToken method returns nil. To enable your app to detect when a user signs out and signs back in, register for changes in iCloud account availability. - Apple Documentation

    http://developer.apple.com/library/mac/#documentation/General/Conceptual/iCloudDesignGuide/Chapters/iCloudFundametals.html

    0 讨论(0)
提交回复
热议问题