Re: CoreData, automatic migration and sandbox problems.
Re: CoreData, automatic migration and sandbox problems.
- Subject: Re: CoreData, automatic migration and sandbox problems.
- From: Dave Fernandes <email@hidden>
- Date: Mon, 28 May 2012 12:01:43 -0400
If you want to check whether a store needs to be migrated and ask the user, you can use [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:::] to get the metadata for the document in question and [NSManagedObjectModel isConfiguration:compatibleWithStoreMetadata:] to check whether that is compatible with the current MOM.
A good place to do these checks is in NSDocumentController before attempting to open the doc.
On 2012-05-28, at 9:59 AM, Samuel Williams wrote:
> Hi,
>
> I'm having trouble with automatic migrations and sandbox.
>
> When the user opens an old file, the automatic migration fails due to no
> write permission to the file.
>
> -
> (BOOL)configurePersistentStoreCoordinatorForURL:(NSURL*)url
> ofType:(NSString*)fileType modelConfiguration:(NSString*)configuration
> storeOptions:(NSDictionary*)storeOptions error:(NSError**)error
>
> {
>
> NSMutableDictionary *options = nil;
>
> if (storeOptions != nil) {
>
> options = [storeOptions mutableCopy];
>
> } else {
>
> options = [[NSMutableDictionary alloc] init];
>
> }
>
>
> [options setObject:[NSNumber numberWithBool:YES]
> forKey:NSMigratePersistentStoresAutomaticallyOption];
>
> [options setObject:[NSNumber numberWithBool:YES]
> forKey:NSInferMappingModelAutomaticallyOption];
>
> *//[options setObject:[NSNumber numberWithBool:YES]
> forKey:NSReadOnlyPersistentStoreOption];*
>
> BOOL result =
> [super configurePersistentStoreCoordinatorForURL:url ofType:fileType
> modelConfiguration:configuration storeOptions:options
>
> error:error];
>
> *//if (*error) {*
>
> * // *** Fails here ****
>
> *// [[NSAlert alertWithError:*error] runModal];*
>
> *//}*
>
> [options release];
>
> return result;
>
> }
>
>
> Just wondering if anyone has a suggestion about how I can avoid writing to
> the file, e.g. forcing the user to re-save or duplicate the document before
> attempting the migration. It works fine for non-sandbox builds.
>
> Kind regards,
> Samuel
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden