How to use Sample Code of “Core Data with iCloud” session 227 in WWDC 2012?

爷,独闯天下 提交于 2019-12-12 07:24:25

问题


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

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();
        }
    }
}

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."

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.

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;"

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.

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

Thanks.

|improve this question

回答1:


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.

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.

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.

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.



来源:https://stackoverflow.com/questions/13718104/how-to-use-sample-code-of-core-data-with-icloud-session-227-in-wwdc-2012

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!