如何使用“iCloud核心数据”的示例代码2012年WWDC会议227? [英] How to use Sample Code of "Core Data with iCloud" session 227 in WWDC 2012?

查看:94
本文介绍了如何使用“iCloud核心数据”的示例代码2012年WWDC会议227?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了几个星期来解决这个问题..
所以请帮我解决这个问题。

I'm strugling few weeks to solve this problem.. so please help me out to solve this problem.

我下载了示例代码来自苹果WWDC 2012的iCloud的核心数据。并试图将它用于我的应用程序但没有任何效果。

I downloaded the sample code of core data with iCloud from apple WWDC 2012. and tried to use it for my application but nothing worked.

当然,我改变了一些代码......但我不确切知道我应该做什么,也找不到任何关于它和教程的网站..

of course, I changed some code little bit.. but I don't know exactly what I should do and can't find any website that saying about it and tutorials..

我已经花了好几个星期,我累了。我知道这是因为我缺乏技巧。

I spended few weeks already and I'm tired. I know this is because of my lack of skill.

我面临的问题是......

problem I'm facing is...

- (void)asyncLoadPersistentStores {
NSError *error = nil;

if ([self loadLocalPersistentStore:&error]) {
    NSLog(@"Added local store");
} else {
    NSLog(@"Unable to add local persistent store: %@", error);
}

//if iCloud is available, add the persistent store
//if iCloud is not available, or the add call fails, fallback to local storage
BOOL useFallbackStore = NO;
if ([self iCloudAvailable]) {
    if ([self loadiCloudStore:&error]) {
        NSLog(@"Added iCloud Store");

        //check to see if we need to seed data from the seed store
        if (SEED_ICLOUD_STORE) {
            //deleted because SEED_ICLOUD_STORE value is false
        }

        //check to see if we need to seed or migrate data from the fallback store
        NSFileManager *fm = [[NSFileManager alloc] init];
        if ([fm fileExistsAtPath:[[self fallbackStoreURL] path]]) {
            //migrate data from the fallback store to the iCloud store
            //there is no reason to do this synchronously since no other peer should have this data
            dispatch_queue_t globalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
            dispatch_async(globalQueue, ^{
                NSError *blockError = nil;
                BOOL seedSuccess = [self seedStore:_iCloudStore
                          withPersistentStoreAtURL:[self fallbackStoreURL]
                                             error:&blockError];
                if (seedSuccess) {
                    NSLog(@"Successfully seeded iCloud Store from Fallback Store");
                } else {
                    NSLog(@"Error seeding iCloud Store from fallback store: %@", error);
                    abort();
                }
            });
        }
    } else {
        NSLog(@"Unable to add iCloud store: %@", error);
        useFallbackStore = YES;
    }
} else {
    useFallbackStore = YES;
}

if (useFallbackStore) {
    if ([self loadFallbackStore:&error]) {
        NSLog(@"Added fallback store: %@", self.fallbackStore);

        //you can seed the fallback store if you want to examine seeding performance without iCloud enabled
        //check to see if we need to seed data from the seed store
        if (SEED_ICLOUD_STORE) {
            //deleted
        }
    } else {
        NSLog(@"Unable to add fallback store: %@", error);
        abort();
        }
    }
}

这是我来源的一部分代码来自CoreDataController.m(WWDC 2012 session 227)
然后,程序在调用loadLocalPersistentStore方法时停止,我收到此错误消息在bundle中找不到本地存储,这可能是构建问题,请确保存储文件正被复制为捆绑资源。

this is part of my source code from CoreDataController.m (WWDC 2012 session 227) then, program stopped when it calls "loadLocalPersistentStore" method and I got this error message "Local store not found in bundle, this is likely a build issue, make sure the store file is being copied as a bundle resource."

我想我得到这个的原因是我没有localStore.sqlite和fallbackStore.sqlite文件之类的例子。所以它会犯错误。

I guess the reason why I got this is that I don't have localStore.sqlite and fallbackStore.sqlite file like the sample. so It makes error.

但是我跳过那部分(评论它),无法连接iCloud,因为现在我收到此错误消息
无法添加iCloud存储:错误Domain = NSCocoaErrorDomain Code = 134100无法完成操作。 (可可错误134100.)UserInfo = 0x1dd93040 {metadata = {
NSPersistenceFrameworkVersion = 419;

but although I skip that part(comment it), can't connect iCloud because now I got this error message "Unable to add iCloud store: Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x1dd93040 {metadata={ NSPersistenceFrameworkVersion = 419;"

我在iOS5上通过iCloud了解了很多关于核心数据的事情它几乎完美地工作。但现在我就像一个愚蠢的人。我无能为力。请帮帮我。

I learned many things about core data with iCloud on iOS5 and It worked almost perfectly. but now I'm like a stupid person. there is nothing I can do. please help me out.

奇怪的是没有关于iCloud app ID的代码,来自apple的示例代码中的url。

strange thing is there is no code that typed about iCloud app ID, url something in sample code from apple.

谢谢。

推荐答案

我还试图从Apple WWDC 2012实施示例iCloud代码时出现问题。我开了一个这是他们在2012年11月15日的回复。

I also had issues with trying to implement the sample iCloud code from the Apple WWDC 2012. I opened a ticket with Apple Developer Support and here was their reply on November 15, 2012.


一些开发人员在采用iCloud和Core Data时遇到了问题来自WWDC的样本。但是,我有一个更新的SharedCoreData示例(从WWDC改进),我认为你应该使用它。 CoreDataController对象仍然存在,但已被清理和改进。我建议先运行该示例,看看它是否在iOS设备之间正确同步。在继续进行更改之前,首先执行此操作非常重要。这样你就可以获得良好的基线。一旦验证了它的工作原理,继续将它的CoreDataController应用到你的应用程序中。

Several developers have been having issues adopting iCloud and Core Data with that sample from WWDC. However, I have an updated SharedCoreData sample (improved from WWDC), that I think you should use instead. The CoreDataController object remains, but has been cleaned up and improved. I suggest running that sample first, see if it syncs properly between iOS devices. This is important to run first before proceeding to make changes. This way you get a good baseline. Once you have verified it works, proceed to adopt it's CoreDataController into your app.

他提到CoreDataController类已经改变了。 AppDelegate也发生了变化。添加了新方法,现在代码更清晰。我几乎让我的iCloud在我的应用程序上工作,但仍然存在初始文件上传的问题。试着解决这个问题吧。使用未经修改的代码运行更新的SharedCoreData应用程序非常有效!所以这是一个不错的起点。

He mentions that the CoreDataController class has changed. The AppDelegate has also changed. New methods have been added and the code is cleaner now. I've almost got my iCloud working on my app but still having an issue with the initial file upload. Trying to fix that now. Running the updated SharedCoreData app with untouched code works perfectly! So it's a nice place to start.

我不知道如何获得这个新代码,除了打开Apple Developer Support的票证(50美元一个)射击)。新项目(仍称为SharedCoreData)的大小仅为1 MB。如果你愿意,我愿意通过电子邮件发送给你。

I don't know how you would get this new code other than opening a ticket with Apple Developer Support (which is 50 bucks a shot). The new project (still named SharedCoreData) is only 1 MB in size. I'd be willing to send it to you via email if you wish.

当我找到我的应用程序的初始文件上传解决方案时,我会在这里发布更新。

I'll post an update here when I figure out the initial file upload solution for my app.

这篇关于如何使用“iCloud核心数据”的示例代码2012年WWDC会议227?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆