如何强制iCloud与核心数据进行同步?

Bri*_*Lee 5 iphone ios5 icloud

我正在使用带有核心数据的iCloud来同步我的应用程序的数据.

我尝试了一切,最后它完美无缺.

但我有一个问题.

有没有办法说iCloud同步?

它在app开始时同步,但另一次.它似乎随机同步.我找不到自己处理它的方法.

任何帮助?

谢谢.

Seb*_*zak 0

您必须使用以下方法强制将任何 NSURL 项目缓存在 iCloud 中:

- (BOOL)addBackupAttributeToItemAtURL:(NSURL *)URL
{
    NSLog(@"URL: %@", URL);
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

    NSError *error = nil;
    BOOL success = [URL setResourceValue: [NSNumber numberWithBool: NO]
                                  forKey: NSURLIsExcludedFromBackupKey error: &error];
    return success;
}
Run Code Online (Sandbox Code Playgroud)

您需要在文档或库目录中下载/创建的每个目录和文件上启动此方法。