【发布时间】:2012-11-22 23:25:38
【问题描述】:
我正在努力解决这个问题。 所以请帮我解决这个问题。
我从苹果 WWDC 2012 下载了带有 iCloud 的核心数据示例代码。并尝试将其用于我的应用程序,但没有任何效果。
当然,我稍微更改了一些代码.. 但我不知道我应该做什么,也找不到任何关于它和教程的网站..
我已经花了几个星期了,我很累。我知道这是因为我缺乏技巧。
我面临的问题是……
- (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”方法时停止,我收到此错误消息“在包中找不到本地存储,这可能是构建问题,请确保将存储文件作为包资源复制。”
我猜我得到这个的原因是我没有像示例这样的 localStore.sqlite 和 fallbackStore.sqlite 文件。所以它会出错。
但是虽然我跳过了那部分(评论它),但无法连接 iCloud,因为现在我收到了这个错误消息 “无法添加 iCloud 商店:Error Domain=NSCocoaErrorDomain Code=134100”操作无法完成。 (可可错误 134100。)“UserInfo=0x1dd93040 {metadata={ NSPersistenceFrameworkVersion = 419;"
我在 iOS5 上使用 iCloud 学到了很多关于核心数据的知识,而且它几乎完美地工作。但现在我就像一个愚蠢的人。我无能为力。请帮帮我。
奇怪的是,在苹果的示例代码中没有输入关于 iCloud 应用 ID 的代码,url 一些东西。
谢谢。
【问题讨论】:
标签: iphone core-data ios6 icloud