시뮬레이터 (지금)가 아니라 장치에서 실행 중일 때이 오류가 발생합니다.CoreData : 오류 : (14) 장치에서 시뮬레이터가 아닌
나뿐만 아니라 시뮬레이터에서 동일한 오류가 발생했고,이 스레드에서 솔루션 구현:이 코드 enter link description here
:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil) {
return __persistentStoreCoordinator;
}
// NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"engliah_FamQuiz.sqlite"];
//=== USE DATABASE FROM MAIN BUNDLE ===//
NSURL *storeURL = [[NSBundle mainBundle] URLForResource:kNewDB withExtension:@"sqlite"];
// Use this for source store - ensures you don't accidentally write to the entities
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:1]
forKey:NSReadOnlyPersistentStoreOption];
// Make sure the WAL mode for Core Data is not enabled
options = @{ NSSQLitePragmasOption : @{@"journal_mode" : @"DELETE"} }; <<< ADDED THIS LINE
// NSDictionary *options = @{NSReadOnlyPersistentStoreOption : @YES, NSSQLitePragmasOption : @{@"journal_mode" : @"DELETE"} };
NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
이 시뮬레이터에서 문제를 해결하지만, 응용 프로그램 충돌 다음 오류가있는 기기에서 :
2014-06-21 15:23:49.828 xxxx[30224:60b] Attempt to add read-only file at path file:///var/mobile/Applications/236047B5-0B0F-443D-ABCF-DCABA0166713/xxxx.app/yyyyy.sqlite read/write. Adding it read-only instead. This will be a hard error in the future; you must specify the NSReadOnlyPersistentStoreOption.
2014-06-21 15:23:49.838 xxxx[30224:60b] CoreData: error: (14) I/O error for database at /var/mobile/Applications/236047B5-0B0F-443D-ABCF-DCABA0166713/xxxx.app/yyyy.sqlite. SQLite error code:14, 'unable to open database file'
2014-06-21 15:23:49.845 xxxx[30224:60b] Unresolved error Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x16e48d80 {NSUnderlyingException=I/O error for database at /var/mobile/Applications/236047B5-0B0F-443D-ABCF-DCABA0166713/xxxx.app/yyyyy.sqlite. SQLite error code:14, 'unable to open database file', NSSQLiteErrorDomain=14}, {
NSSQLiteErrorDomain = 14;
NSUnderlyingException = "I/O error for database at /var/mobile/Applications/236047B5-0B0F-443D-ABCF-DCABA0166713/xxxx.app/yyyy.sqlite. SQLite error code:14, 'unable to open database file'";
시뮬레이터에는 오류가 없습니다. 또한 첫 번째 오류는 새로운 것입니다.
전개 대상 6.1
내 대답을 쓰고 난 다음 질문에 같은 코드를 추가 한 것을 보았습니다. '// NSDictionary * options = @ {NSReadOnlyPersistentStoreOption : @YES, NSSQLitePragmasOption : @ {@ "journal_mode": @ "DELETE"} };'. - 이제 실제 코드가 어떤 것입니까? –
나는 둘 다 시험했다. – PeterK
SQLite 파일이 앱과 함께 제공된다고 가정합니다. 데이터베이스를 만들 때 * WAL 모드를 비활성화 했습니까? –