2012-08-06 80 views
0

我制作了一个Core Data应用程序,并且我想将file.sqlite保存到默认的不同目录中。我遇到了这个SO thread,然后发布this SO question,该项目似乎是compling,但我的file.sqlite没有得到保存在我指定的位置。我创建了一个方法,并在AppDelegate.m文件中添加了一些代码,但storeURL变量仍然将file.sqlite保存在默认的“文档目录”中。如何调用我在AppDelegate.m文件中创建的方法来指定storeURL的正确位置变量?越狱 - 为Core Data应用程序重新安置“Documents”目录

我应该改变,

NSURL *storeURL = [NSURL fileURLWithPath: [docPath stringByAppendingPathComponent:@"Accounts.sqlite"]]; 

NSURL *storeURL = [NSURL fileURLWithPath: [documentsDirectoryPath stringByAppendingPathComponent:@"Accounts.sqlite"]]; 

也将这种破解的iOS模拟器支持?

+1

我很抱歉,如果这听起来不礼貌,但我认为一切都在评论你的前一个问题[http://stackoverflow.com/questions有人说/ 11812576/IOS-如何对变化的文件目录。如果您不知道如何调用自己的方法'documentsDirectoryPath',并且如果您不使用调试器来找出您的'storeURL'错误的原因,那么我们无法帮助您。 – 2012-08-07 10:48:37

回答

1

我通过保持默认文件路径模拟器,然后建立一个不同的文件路径设备解决了这个问题。下面的代码是在我的AppDelegate.m文件

// add conditional code for simulator and iDevice 
#if TARGET_IPHONE_SIMULATOR 
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

NSString *docPath = [documentPaths objectAtIndex:0]; 

NSURL *storeURL = [NSURL fileURLWithPath: [docPath stringByAppendingPathComponent:@"Accounts.sqlite"]]; 
#else 
// jailbroken path - /var/mobile/Library/KegCop/ 
NSString *docPath = self.documentsDirectoryPath; 

NSURL *storeURL = [NSURL fileURLWithPath: [docPath stringByAppendingPathComponent:@"Accounts.sqlite"]]; 
#endif 
相关问题