【发布时间】:2014-12-13 05:13:51
【问题描述】:
我已经尝试了所有内容并阅读了所有主题,但我不知道为什么 NSUbiquitousKeyValueStore 没有存储在 iCloud 上。
• 创建了特定的应用 ID
• 为该 App ID 启用 iCloud
• 创建的配置文件
• 在项目上启用 iCloud
• 设置 Key Value 的权利:$(TeamIdentifierPrefix)$(CFBundleIdentifier)
• 在设备上打开 iCloud Drive
但是 NSUbiquitousKeyValueStore 只是在本地保存。当我重新安装应用程序时,它不会从 iCloud 获取信息。
这就是我正在尝试的方式:
NSUbiquitousKeyValueStore *cloudStore = [NSUbiquitousKeyValueStore defaultStore];
if ([[cloudStore stringForKey:@"testString"] length] == 0) {
NSLog(@"Nothing in iCloud - setting a value...");
[cloudStore setString:@"I'm live in iCloud!" forKey:@"testString"];
[cloudStore synchronize];
[[NSUbiquitousKeyValueStore defaultStore] synchronize];
} else {
NSString *result = [cloudStore stringForKey:@"testString"];
NSLog(@"Found something in iCloud - here it is: %@", result);
}
[self registerForiCloudNotificatons];
如果我删除应用程序或在新设备上尝试,它在 iCloud 上找不到任何东西。
所以我尝试了这个来确定 iCloud 是否正常工作:
NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
if (ubiq) {
NSLog(@"iCloud at %@", ubiq);
} else {
NSLog(@"No iCloud access, %@", ubiq);
}
这总是返回“没有 iCloud 访问权限”,我不知道为什么。无论我做什么 URLForUbiquityContainerIdentifier 总是返回 nil。
我在启用了 iCloud 的 iOS 8 设备上运行。
我错过了什么吗?
谢谢!
【问题讨论】:
-
经过几天的努力,我简单地从 iCloud 注销并再次登录。现在一切正常...... URLForUbiquityContainerIdentifier 仍然返回 nil,所以我无法检查 iCloud 是打开还是关闭,但至少它正在同步并将数据保存在云端。
标签: ios icloud nsubiquitouskeyvaluestore