我试图用NSUbiquitousKeyValueStore存储键值。在安装应用程序时,它们似乎存储得很好,但是如果我从设备上删除应用程序并再次运行应用程序,关键值似乎就丢失了。这是预期的行为,还是我错过了什么?
我存储和检索的值如下:
-(void)setString:(NSString*)stringValue forKey:(NSString*)keyValue {
NSUbiquitousKeyValueStore *iCloudStore = [NSUbiquitousKeyValueStore defaultStore];
[iCloudStore setString:stringValue forKey:keyValue];
[iCloudStore synchronize];
}
-(NSString*)getStringForKey:(NSString*)keyValue {
NSUbiquitousKeyValueStore *iCloudStore = [NSUbiquitousKeyValueStore defaultStore];
return [iCloudStore stringForKey:keyValue];
}我已经查过了:
补充问题-
发布于 2015-01-14 19:47:15
您是否为中的应用程序id启用了应用程序服务中的iCloud?在此之后,您还必须为应用程序创建一个配置文件。
我在代码中看到的唯一区别是"name:“参数。您需要指定要观察
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector (storeDidChange:)
name: NSUbiquitousKeyValueStoreDidChangeExternallyNotification
object: [NSUbiquitousKeyValueStore defaultStore]];您的代码在我的环境中抛出一个警告。
Instance method '-addObserver:selector:object:' not found (return type defaults to 'id')
我还使用了setObject:forKey:而不是setString:forKey:
https://stackoverflow.com/questions/27825466
复制相似问题