Core data UIAlertView不会从Appdelegate显示

Core data UIAlertView不会从Appdelegate显示,core-data,ios6,migration,uialertview,Core Data,Ios6,Migration,Uialertview,我正在进行核心数据迁移。我试图处理持久存储不匹配且应用程序崩溃时的异常。但在它崩溃之前,我想让用户知道(通过警报视图),他需要先卸载应用程序,然后重新安装。我有persistentStoreCoordinator访问器方法中警报视图的代码,但警报视图从未显示 代码如下: - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (__persistentStoreCoordinator != nil) { r

我正在进行核心数据迁移。我试图处理持久存储不匹配且应用程序崩溃时的异常。但在它崩溃之前,我想让用户知道(通过警报视图),他需要先卸载应用程序,然后重新安装。我有persistentStoreCoordinator访问器方法中警报视图的代码,但警报视图从未显示

代码如下:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{

  if (__persistentStoreCoordinator != nil) {
    return __persistentStoreCoordinator;
}

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"ExchangeMail.sqlite"];

NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];

// Dictionary required to store the details of psc on the disk,
NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType URL:storeURL error:&error];

// This BOOL value is required to check whether a migration is required or not.
BOOL pscCompatibile = [[self managedObjectModel] isConfiguration:nil compatibleWithStoreMetadata:sourceMetadata];
NSLog(@"Migration needed? %d", !pscCompatibile);


NSMutableDictionary *options = [[NSMutableDictionary alloc] init];
[options setValue:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption];
[options setValue:[NSNumber numberWithBool:YES] forKey:NSInferMappingModelAutomaticallyOption];

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Non-matching Database File" message:@"The model configuration used to open the store is compatible with the one that was used to create the store. Please Uninstall the App and try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[__persistentStoreCoordinator lock];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {

 //        dispatch_queue_t queue = NULL;
 //        queue = dispatch_get_main_queue();
 //        dispatch_async(queue, ^{
 //            [[NSFileManager defaultManager]removeItemAtURL:storeURL error:nil];
 //            
 //            [self.myAlertView show];
 //        });

    [self.myAlertView show];
    //exit(-1);
}

[__persistentStoreCoordinator unlock];


if(!pscCompatibile){
    isMigrationRequired = YES;
}

return __persistentStoreCoordinator;

}

崩溃并不完全是模型迁移的工作方式。您这样做而不是实际迁移到新模型是有原因的吗?其中一位开发人员在模式文件发布后已经重写了该模式文件。因此,我想我们是否可以让用户知道存储配置不匹配,用户需要卸载应用程序。您似乎从未在代码中的任何位置设置
self.myAlertView
。执行
self.myAlertView=[[UIAlertView alloc]init…
show
您已经创建的
alertView
。在数据模型文件上没有版本控制?没有备份?您的目标是一个糟糕的用户体验,最好避免这样做。