Ios 未调用iCloud键值存储更改(NSUbiquitousKeyValueStoreDidChangeExternallyNotification)
Ios 未调用iCloud键值存储更改(NSUbiquitousKeyValueStoreDidChangeExternallyNotification),ios,swift,icloud,key-value,Ios,Swift,Icloud,Key Value,NSUbiquitousKeyValueStoreDidChangeExternallyNotification根本不会被调用 var keyStore: NSUbiquitousKeyValueStore? viewDidLoad{ NSNotificationCenter.defaultCenter().addObserver(self, selector: "ubiquitousKeyValueStoreDidChange:", name
NSUbiquitousKeyValueStoreDidChangeExternallyNotification根本不会被调用
var keyStore: NSUbiquitousKeyValueStore?
viewDidLoad{
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "ubiquitousKeyValueStoreDidChange:",
name: NSUbiquitousKeyValueStoreDidChangeExternallyNotification,
object: keyStore)
userDefinedLabelOne.text = keyStore?.stringForKey("userDefinedStringOne") <---this is changed
}
func ubiquitousKeyValueStoreDidChange(notification: NSNotification) {
println("Changed") <---- Not called
}
var密钥库:NSUbiquitousKeyValueStore?
viewDidLoad{
NSNotificationCenter.defaultCenter().addObserver(self,
选择器:“ubiquitousKeyValueStoreDidChange:”,
名称:NSUbiquitousKeyValueStoreDidChangeExternallyNotification,
对象:密钥库)
userDefinedLabelOne.text=keyStore?.stringForKey(“userDefinedStringOne”)看看。这段代码适合我:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
prepareKeyValueStoreObserver()
return true
}
func syncKeyValueStore() {
let kvStore: NSUbiquitousKeyValueStore = NSUbiquitousKeyValueStore.defaultStore();
kvStore.synchronize()
}
func prepareKeyValueStoreObserver(){
let kvStore: NSUbiquitousKeyValueStore = NSUbiquitousKeyValueStore.defaultStore();
let notificationsCenter: NSNotificationCenter = NSNotificationCenter.defaultCenter()
notificationsCenter.addObserver(self, selector: "ubiquitousKeyValueStoreDidChange:", name: NSUbiquitousKeyValueStoreDidChangeExternallyNotification, object: kvStore)
syncKeyValueStore()
}
通过注销iCloud帐户并重新登录所有已开始正常工作的帐户我可能无法正确实施它,但这对Meeded不起作用:需要注意的是,当你的应用程序启动时,你应该立即调用synchronize,以便你的应用程序知道在启动时检查iCloud键值存储的更改。是的,已经这样做了ne和确认为同步,但记录没有愚蠢的方式。这实际上起了作用。哇,苹果,只是哇。谢谢你,巴德