2

Currently the program I am working on uses Core Data, and stores "Account" information in a file called Accounts.sqlite This file is stored in the Documents directory inside the long string of characters, i.e. A89C1398-A7BE-44F1-A337-DABA9C66AF1D So I want to save / create the file for the application in /var/mobile/Library/KegCop I found this SO question and I made the necessary changes, deleted my app off the phone, clicked the Run button in Xcode and the app built and ran fine. However the Accounts.sqlite file was still in the Documents directory.

I added / modified the follow code to the AppDelegate.m file,

// default sqlite file path
// NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Accounts.sqlite"];

// jailbroken path - /var/mobile/Library/KegCop/
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *docPath = [documentPaths objectAtIndex:0];

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

and then created the following method in the AppDelegate.m file,

// set path for documents in jailbreak environment
+(NSString *)documentsDirectoryPath
{
#ifdef JAILBREAK

NSString *documentPath =@"/var/mobile/Library/KegCop";

if (![[NSFileManager defaultManager] fileExistsAtPath:documentPath])
{
    [[NSFileManager defaultManager] createDirectoryAtPath:documentPath
                              withIntermediateDirectories:NO
                                               attributes:nil
                                                    error:NULL];
}

return documentPath;

#else

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [documentPaths objectAtIndex:0];

#endif
}
Community
  • 1
  • 1
ipatch
  • 3,933
  • 8
  • 60
  • 99
  • 1
    I cannot see that you actually use the `documentsDirectoryPath` method to compute the `storeURL`. – Martin R Aug 05 '12 at 06:40
  • 1
    Btw it won't compile because of typo in `NSFIleManager`. Are you sure that `JAILBREAK` is defined? – Martin R Aug 05 '12 at 06:43
  • @MartinR I was wondering about that? How would I go about defining `JAILBREAK`? – ipatch Aug 05 '12 at 14:41
  • If your project uses a precompiled header (.pch) file, then add `#define JAILBREAK` to that file. – Martin R Aug 05 '12 at 15:29
  • @MartinR it indeed does use the `.pch` file. I added `#define JAILBREAK` to the end of the file, and now the program is crashing when it starts. I'm getting the following errors, 2012-08-05 10:46:16.924 KegCop[1265:707] Initializing IntelliStatusBarIcons v0.93 2012-08-05 10:46:16.941 KegCop[1265:707] Initialized listener for icon updates Couldn't register com.chrisrjones.KegCop with the bootstrap server. Error: unknown error code. This generally means that another instance of this process was already running or is hung in the debugger. – ipatch Aug 05 '12 at 15:49
  • I closed the process running on the phone, and then tried running the program again and it just crashes at startup. – ipatch Aug 05 '12 at 15:50
  • I have the same problem sometimes with Xcode. The only solution seems to be to reboot your computer. – Martin R Aug 05 '12 at 15:51
  • reboot the computer? really? I'll try restarting Xcode, and if that doesn't work then I'll try restarting the computer. – ipatch Aug 05 '12 at 16:08
  • I rebooted, then clicked `Run` in Xcode, and I am still getting the same crash :-/ – ipatch Aug 05 '12 at 16:18
  • 1
    I know only that `Couldn't register XXX with the bootstrap server` is a well-known problem, see e.g. http://stackoverflow.com/questions/788277/iphone-strange-error-when-testing-on-simulator. For crashes in your code you should use the debugger to localize the problem. – Martin R Aug 05 '12 at 16:26
  • the only thing I can think of is that I added the `#define JAILBREAK` to the .pch and now I am getting this error. :-/ – ipatch Aug 05 '12 at 16:28
  • @MartinR, I restarted the phone, and now the app isn't crashing at launch (yay). However the `Accounts.sqlite` file is still being created in the `Documents` folder. I added the code listed above, and I added `#define JAILBREAK` to the `.pch` file. I also deleted the app from the phone, and then clicked `Run` in Xcode to build and run the app on the device again, and then I ssh into the phone and check to see if the `Accounts.sqlite` is being created in the `Documents` folder and it is (sigh). – ipatch Aug 05 '12 at 16:42
  • Please read my first comment again! Use the debugger to check the value of `storeURL`! – Martin R Aug 05 '12 at 16:47
  • @MartinR, Ahh, I see what your saying, in order to use the newly created method, would i do something like `NSURL *storeURL = [NSURL fileURLWithPath: [documentsDirectoryPath stringByAppendingPathComponent:@"Accounts.sqlite"]];` – ipatch Aug 05 '12 at 16:56

0 Answers0