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 (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/dave.fernandes%40utoronto.ca
> 
> This email sent to dave.fernan...@utoronto.ca


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to