Сбой при вызове addpersistentstorewithtype - PullRequest
0 голосов
/ 19 сентября 2018

Я создаю NSPersistentStore с кодом ниже, но он вылетает с ошибкой, опубликованной ниже.

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

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

// Check if we need to copy initial database store
NSString *storePath = [[self applicationDocumentsDirectory]
                       stringByAppendingPathComponent: PersistentStoreFilename];
//[self checkPersistentStore:storePath];
NSURL *storeUrl = [NSURL fileURLWithPath:storePath];
// Enable automatic lightweight migration
NSDictionary *options = @{
                          NSMigratePersistentStoresAutomaticallyOption : @YES,
                          NSInferMappingModelAutomaticallyOption : @YES
                          };
NSError *error = nil;
NSDictionary *fileAttributes = [NSDictionary dictionaryWithObject:NSFileProtectionComplete forKey:NSFileProtectionKey];
NSLog(@"fileAttributes ---- %@",fileAttributes);
NSLog(@"before file attributes - storePath ---- %@",storePath);
[[NSFileManager defaultManager] setAttributes:fileAttributes ofItemAtPath:storePath error:&error];

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

NSLog(@"1.persistentStoreCoordinator ---- %@",persistentStoreCoordinator);
NSLog(@"2.applicationDocumentsDirectory ---- %@",[self applicationDocumentsDirectory]);
NSLog(@"3.PersistentStoreFilename ---- %@",PersistentStoreFilename);
NSLog(@"4.storePath ---- %@",storePath);
NSLog(@"4.storeUrl ---- %@",storeUrl);

NSLog(@"5)persistentStoreCoordinator ---- Error loading core data database");

if(![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
                                             configuration:nil URL:storeUrl options:options error:&error]) {
    /*Error for store creation should be handled in here*/

    // REA - removing current store and replacing with one from bundle
    //        NSFileManager *fileManager = [NSFileManager defaultManager];
    //        [fileManager removeItemAtPath:storePath error:nil];
    //        [self checkPersistentStore:storePath];
    NSLog(@"First attempt addPersistentStoreWithType error %@, %@", error, [error userInfo]);
    if(![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
                                                 configuration:nil URL:storeUrl options:options error:&error]) {
        // Even the bundle version isn't loading - something really bad happened and we can't run
        NSLog(@"Second attempt addPersistentStoreWithType error %@, %@", error, [error userInfo]);
        NSLog(@"6)persistentStoreCoordinator ---- Error loading core data database");
        abort();
    }
}

return persistentStoreCoordinator;
}

Вызывает сбой и ниже nslog от устройства.

перед атрибутами файла - storePath ---- /var/mobile/Containers/Data/Application/AA4EF2AA-1E72-4BC9-A939-732A1BB65E71/Documents/iPhoneCoreData.sqlite

1.persistentStoreCoordinator ----

2.applicationDocumentsDirectory ---- / var / mobile / Containers / Data / Application / AA4EF2AA-1E72-4BC9-A939-732A1BB65E71 / Documents

3.PersistentStoreFilename ---- iPhoneCoreData.sqlite

4.storePath ---- /var/mobile/Containers/Data/Application/AA4EF2AA-1E72-4BC9-A939-732A1BB65E71/Documents/iPhoneCoreData.sqlite

4.storeUrl ---- файл: ///var/mobile/Containers/Data/Application/AA4EF2AA-1E72-4BC9-A939-732A1BB65E71/Documents/iPhoneCoreData.sqlite

СбойЖурналы:

Тип исключения: EXC_CRASH (SIGKILL) Коды исключений: 0x0000000000000000, 0x0000000000000000 Примечание об исключении: EXC_CORPSE_NOTIFY Причина завершения: Пространство имен SPRINGBOARD, код 0x8badf00d Описание завершения: SPRINGBOARD, нарушение режима сторожевого таймера создания сцены: com.united.UnitedAgentMobileApp исчерпало допустимое время реального (настенного времени) времени 19,27 секунды ||ProcessVisibility: передний план |ProcessState: выполняется |WatchdogEvent: сцена-создание |WatchdogVisibility: Передний план |WatchdogCPUStatistics: (| "Истекшее общее время ЦП (в секундах): 21,220 (пользователь 21,220, система 0,000), 53% ЦП", | "Истекшее время ЦП приложения (в секундах): 19,319, 48% ЦП" |) Инициируется потоком: 0

Back Trace:

Имя потока 0: Очередь отправки: SQLQueue 0x117dc0080 для UnitediPhoneCoreData.sqlite Поток 0 Сбой: 0 libcompression.dylib 0x00000001841865d8 zlibDecodeBufferSafe.dylib 0x000000018418747c zlib_decode_stream_process + 288 3 CoreData 0x000000018530d92c - [NSSQLiteConnection _decompressedModelWithData:] + 188 4 CoreData 0x000000018530dc5c - [NSSQLiteConnection fetchCachedModel] + 552 5 CoreData 0x00000001852e18b0 __34- [NSSQLCore cachedModelWithError:] _ block_invoke + 112 6 CoreData 0x00000001852301d4 - [NSSQLStoreRequestContext executeRequestUsingConnection:] +248 7 CoreData 0x00000001852b2118 __52- [NSSQLDefaultConnectionManager handleStoreRequest:] _ block_invoke + 848 libdispatch.dylib 0x000000018239aa14 _dispatch_client_callout + 16 9 libdispatch.dylib 0x00000001823a3618 _dispatch_queue_barrier_sync_invoke_and_complete + 56 10 CoreData 0x00000001852b2014 - [NSSQLDefaultConnectionManager handleStoreRequest:] + 256 11 CoreData 0x00000001853a2524 - [NSSQLCoreDispatchManager routeStoreRequest:] + 264 12 CoreData 0x00000001852e3fdc - [NSSQLCore dispatchRequest: withRetries] +:236 13 CoreData 0x00000001852e1738 - [NSSQLCore cachedModelWithError:] + 112 14 CoreData 0x00000001852e297c + [NSSQLCore cachedModelForPersistentStoreWithURL: варианты: ошибка:] + 688 15 CoreData 0x00000001853363ac - [NSStoreMigrationPolicy sourceModelForStoreAtURL: метаданные: ошибка:] + +1256 16 CoreData 0x00000001853379c8 - [NSStoreMigrationPolicy + 1653192 (InternalMethods) _gatherDataAndPerformMigration:] + 772 17 CoreData 0x00000001852bba34 __91- [NSPersistentStoreCoordinator addPersistentStoreWithType: конфигурация: URL-адрес: параметры: ошибка:] _ block_invoke + 2896 18 CoreData 0x000056c0f9BlockToNSPersistentStoreCoordinatorPerform + 21219 libdispatch.dylib 0x000000018239aa14 _dispatch_client_callout + 16 20 libdispatch.dylib 0x00000001823a3618 _dispatch_queue_barrier_sync_invoke_and_complete + 56 21 CoreData 0x00000001852b7944 _perform + 200 22 CoreData 0x00000001851adfa4 - [NSPersistentStoreCoordinator addPersistentStoreWithType: конфигурация: URL: опции: ошибка:] + 384

1 Ответ

0 голосов
/ 20 сентября 2018

Таким образом, мы следовали схеме выключателя и следовали за сообщением в блоге ниже, чтобы решить проблему.

https://code.tutsplus.com/tutorials/core-data-from-scratch-migrations--cms-21844

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...