0

我遇到了核心数据的问题。

简单的应用程序是创建文档,第一个视图控制器将显示我创建的所有文档,这些文档存储在核心数据数据库中。

当我在 iOS 模拟器上运行程序时,它运行良好。当我在将 iPad 与 mac 连接时在 iOS 设备上运行该应用程序时,它也可以正常工作。

但是当我断开 iPad 与 Mac 的连接,或者停止在 xCode 中运行程序时,该应用程序仍然可以在我的 iPad 上运行。但是之前创建的所有文档都没有加载。我仍然可以创建文档,并且它们正确显示在视图控制器上。但是当我停止应用程序并再次启动它时,书架仍然是空的......那些文档不是从核心数据数据库加载的。

你能帮我解决这个问题吗?

谢谢!

4

1 回答 1

0

If your app is deployed to iOS 5.1 or newer, then you should be using the "Documents/Application Support" folder, and also marking the documents if you do not want them backed up to iCloud. I am finding I need to create "Application Support" if its not there. This is the code I use:

    NSFileManager *manager = [NSFileManager defaultManager];
    NSString *appSupportDir = [self applicationAppSupportDirectory];
    if(![manager fileExistsAtPath:appSupportDir]) {
        __autoreleasing NSError *error;
        BOOL ret = [manager createDirectoryAtPath:appSupportDir withIntermediateDirectories:NO attributes:nil error:&error];
        if(!ret) {
            NSLog(@"ERROR app support: %@", error);
            exit(0);
        }
    }

- (NSString *)applicationAppSupportDirectory
{
    return [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject];
}
于 2012-09-09T17:50:36.693 回答