5

How would I detect specifically if a user is signed into iCloud? Checking the return value of URLForUbiquityContainerIdentifier is very limited:

1) It can't distinguish between a user not being signed into iCloud versus other scenarios, e.g. iCloud not enabled. 2) It doesn't appear to change its behavior if a user signs into iCloud from the Settings app while the game is still running in the background, then returns to the app to try to access iCloud services.

Is there a more reliable way to detect specifically if a user is signed in?

4

3 回答 3

5

此外,从 iOS 6 开始,还有一个方法[[NSFileManager defaultManager] ubiquityIdentityToken],它会告诉您 iCloud 是否可用以及用户是否切换了帐户

于 2013-07-17T14:25:00.347 回答
1

无法区分“用户未登录”和“iCloud 未启用”。您在您的应用程序中了解的是您的应用程序当前是否可以访问 iCloud,但如果答案是否定的,那么您不知道为什么。

但是,您的问题 #2 有一个解决方案 - 观察NSUbiquityIdentityDidChangeNotification。它会在整个 iCloud 状态发生变化时触发——用户登录、用户注销、用户切换帐户。

于 2013-01-08T01:01:03.670 回答
0
func isUserSignedIntoICloud() -> Bool {
    return FileManager.default.ubiquityIdentityToken != nil
}
于 2019-05-21T15:51:37.763 回答