gpt4 book ai didi

iphone - NSInternalInconsistencyException(执行 SQL 字符串 'INSERT INTO Y_UBMETA(YPEERID, YTRANSACTIONNUMBER) 期间出错)

转载 作者:行者123 更新时间:2023-12-03 18:36:52 25 4
gpt4 key购买 nike

iOS iCloud

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“执行 SQL 字符串“INSERT INTO Y_UBMETA(YPEERID, YTRANSACTIONNUMBER) 期间出错”

Unresolved 错误错误域=NSCocoaErrorDomain代码=134312“存储元数据恢复似乎失败,请尝试再次将存储添加到协调器。如果不成功,请将数据迁移到新的通用化持久存储。” UserInfo=0xdba5b80 {NSLocalizedDescription=存储元数据恢复似乎失败,请尝试再次将存储添加到协调器。如果不成功,请将数据迁移到新的通用化持久存储。}, { NSLocalizedDescription = "存储元数据恢复似乎失败,请尝试再次将存储添加到协调器。如果不成功,请将数据迁移到新的通用化持久存储。";

如何解决这个问题?因为它是 iCloud 的内部查询。我将我的代码块放在我编写的方法的下面..

    - (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    NSLog(@"persistentStoreCoordinator:%@",[persistentStoreCoordinator_ description]);
    if((persistentStoreCoordinator_ != nil))
    {
        return persistentStoreCoordinator_;
    }

    NSLog(@"persistentStoreCoordinator:%@",[persistentStoreCoordinator_ description]);
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreDataModel.sqlite"];

    persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];


    NSPersistentStoreCoordinator* psc = persistentStoreCoordinator_;

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
   
           
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSFileManager *fileManager = [NSFileManager defaultManager];

        // Migrate datamodel
        NSDictionary *options = nil;

        // this needs to match the entitlements and provisioning profile
        NSURL *cloudURL = [fileManager URLForUbiquityContainerIdentifier:nil];

        NSLog(@"cloudURL:%@",cloudURL);

            //NSString* coreDataCloudContent = [[cloudURL path] stringByAppendingPathComponent:@"Data"];  
           
           cloudURL = [cloudURL URLByAppendingPathComponent:@"Data"];                                                                                                                                  

       // NSLog(@"coreDataCloudContent:%@",coreDataCloudContent);


       //if ([coreDataCloudContent length] != 0 && [[defaults objectForKey:@"allMetadataFlag"] isEqualToString:@"YES"])
           
       if (cloudURL )//&& [[defaults objectForKey:@"allMetadataFlag"] isEqualToString:@"YES"])
           
        {
            // iCloud is available
           // cloudURL = [NSURL fileURLWithPath:coreDataCloudContent];

            NSLog(@"cloudURL:%@",cloudURL);

            options = [NSDictionary dictionaryWithObjectsAndKeys:
                       [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                       [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
                       @"SecureAssistant.store", NSPersistentStoreUbiquitousContentNameKey,
                       cloudURL, NSPersistentStoreUbiquitousContentURLKey,nil];
        }
        else
        {
            // iCloud is not available
            options = [NSDictionary dictionaryWithObjectsAndKeys:
                       [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                       [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,nil];
        }
            NSError *error = nil;
        [psc lock];
        if (![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
        {
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        }
        [psc unlock];

        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"asynchronously added persistent store!");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"RefetchAllDatabaseData" object:self userInfo:nil];
        });

    });
   
   return persistentStoreCoordinator_;
}

最佳答案

我遇到了同样的问题,它发生是因为我从 Xcode 更改了数据模型的属性,而不是通过代码从我的应用程序更改了数据模型的属性。我通过从 iCloud 删除 SQLite 文件并从设备中删除应用程序然后重建来解决了这个问题。它对我有用。

关于iphone - NSInternalInconsistencyException(执行 SQL 字符串 'INSERT INTO Y_UBMETA(YPEERID, YTRANSACTIONNUMBER) 期间出错),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11373449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com