I am using this Xcode template for core data.
On the delegate, I have this method:
- (NSURL *)applicationDocumentsDirectory {
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
but this requires iOS4.
I am trying to make the app compatible with 3.0.
So, I have converted this method to:
- (NSURL *)applicationDocumentsDirectory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [NSURL URLWithString:documentsDirectory];
}
but when coredata tries to use the store URL on
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"MyFile.sqlite"];
if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
it crashes on the IF line with the message:
CoreData SQL stores only support file URLs (got /var/mobile/Applications/BB312A7E-6AE1-4BA2-AD87-6B96D8855CC6/Documents/MyFile.sqlite).'
but StoreURL is a NSURL!
Any clues? Thanks
Try doing:
NSString *pathToYourSqliteFile = @"/your/path/here";
NSURL *storeURL = [NSURL fileURLWithPath: isDirectory:NO];
See if that does the trick.
See CoreData application directory crashes on iOS3
The suggestion from Surfdev works ok on 3.1.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With