【问题标题】:What is iCloud doing during the initial sync?iCloud 在初始同步期间在做什么?
【发布时间】:2011-12-22 13:14:51
【问题描述】:

我想将我的 Core Data 鞋盒应用与 iCloud 同步。 Apple 提供的示例项目展示了如何设置 NSPersistentStoreCoordinator 以启用 iCloud。代码大致是这样的:

persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];

NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:@"com.company.app", NSPersistentStoreUbiquitousContentNameKey, cloudURL, NSPersistentStoreUbiquitousContentURLKey,nil];

[psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]);

问题是:如果 iCloud 中已经存储了数据,则此方法需要永远返回persistentStoreCoordinator。如果我同步执行,我会看到几分钟的空白屏幕,如果我异步执行,我的应用程序将完全无法使用,因为我无法与 Core Data 交互。

肯定有一种方法可以像没有 iCloud 一样添加持久存储,然后让 iCloud 异步工作?

基本上,我的问题是,iCloud 在初始同步期间做了什么,我可以先让我的 persistentStoreCoordinator 让数据在后台同步吗?

【问题讨论】:

    标签: ios cocoa-touch cocoa core-data icloud


    【解决方案1】:

    当您使用 iCloud 同步 Core Data 时,您需要在单独的线程上加载存储。看看:

    https://devforums.apple.com/thread/126670

    这演示了商店的异步加载。

    【讨论】:

    • 我认为加载缓慢可能是 iCloud 错误,因为我不再看到加载时间过长。异步是要走的路。
    • 虽然 Apple 的示例是异步创建持久存储,但我必须等待很长时间才能在设备 B 上完全启动应用程序。知道我做错了什么吗?
    • 这是一个在单独线程上加载商店的好模型。但是,因为它锁定了线程,如果您尝试从主线程访问存储,它会阻塞,直到同步完成并且线程被解锁。这很烦人。
    • 你找到解决办法了吗?
    • kurtzmarc,你能帮我解决这个问题吗?谢谢。 stackoverflow.com/questions/13718104/…
    猜你喜欢
    • 2012-05-25
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2020-12-17
    相关资源
    最近更新 更多