gpt4 book ai didi

ios - DNS Ubiquiti Identity DidChangeNotification 不会通过 cloudkit 触发

转载 作者:行者123 更新时间:2023-11-30 14:15:13 24 4
gpt4 key购买 nike

这是我当前的代码

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 帐户)。

最佳答案

在 Swift 中,我有时需要在函数前面添加 @objc 以便 NSNotificationCenter 找到它。

所以而不是

func handleIdentityChange(notification:NSNotification) {

我会尝试

@objc func handleIdentityChange(notification:NSNotification) {

关于ios - DNS Ubiquiti Identity DidChangeNotification 不会通过 cloudkit 触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31273770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com