【发布时间】:2015-07-07 16:02:34
【问题描述】:
这是我当前的代码
func applicationDidBecameActive(notification:NSNotification) {
println("Application is active")
NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleIdentityChange:", name: NSUbiquityIdentityDidChangeNotification, object: nil)
}
func applicationBecameInactive(notification:NSNotification) {
println("Application is inactive")
NSNotificationCenter.defaultCenter().removeObserver(self, name: NSUbiquityIdentityDidChangeNotification, object: nil)
}
func handleIdentityChange(notification:NSNotification) {
println("this is working")
let fileManager = NSFileManager()
if let token = fileManager.ubiquityIdentityToken {
println("New token is \(token)")
}
else {
println("User has logged out of iCloud")
}
}
“应用程序处于活动状态”和“应用程序处于非活动状态”正常工作。那里没有问题。
我无法让它“这工作正常”。通过登录不同的 iCloud 帐户或退出 iCloud 帐户。
我在模拟器和实际设备上试过。
请帮我解决这个问题或建议替代方法来实现相同的目标(更改 iCloud 帐户)。
【问题讨论】:
-
如果您想更改其他用户答案的含义,而不是对其进行编辑,请在对该答案的评论中说明您认为应该更改的内容,或添加您自己的答案。
-
尝试在 willEnterForeground 上连接通知处理程序。 didBecomeActive 为时已晚。
-
我试过了。它仍然不起作用。感谢您的帮助,但我现在在 iOS 9 中使用 CKAccountChangeNotification。