gpt4 book ai didi

objective-c - 有时不调用 NSUbiquitousKeyValueStoreDidChangeExternallyNotification

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:50:08 26 4
gpt4 key购买 nike

我为 iCloud key-value Store 编写了代码

    [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyValueStoreChanged:)
name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification
object:nil];
LOG(@"sync");
[[NSUbiquitousKeyValueStore defaultStore] synchronize];

当我删除应用程序并重新安装它时,通常会调用观察者方法,但有时不会调用。

为什么?只是网络问题?

最佳答案

我有一个类似的问题,无论我等了多久,NSUbiquitousKeyValueStoreDidChangeExternallyNotification 都没有在安装后的第一次启动时触发。在 NSUBiquitousKeyValueStore 中设置一个初始 key 似乎可以解决这个问题。

将观察者添加到默认存储后,我立即调用:

[[NSUbiquitousKeyValueStore defaultStore] setString:@"testValue" forKey:@"testKey"];
[[NSUbiquitousKeyValueStore defaultStore] synchronize];

我对要同步的实际数据使用不同的 key (即不是 testKey)。

关于objective-c - 有时不调用 NSUbiquitousKeyValueStoreDidChangeExternallyNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12635960/

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