Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未调用iCloud键值存储更改(NSUbiquitousKeyValueStoreDidChangeExternallyNotification)_Ios_Swift_Icloud_Key Value - Fatal编程技术网

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和确认为同步,但记录没有愚蠢的方式。这实际上起了作用。哇,苹果,只是哇。谢谢你,巴德