2014-06-21 3 views
1

시뮬레이터 (지금)가 아니라 장치에서 실행 중일 때이 오류가 발생합니다.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

+0

내 대답을 쓰고 난 다음 질문에 같은 코드를 추가 한 것을 보았습니다. '// NSDictionary * options = @ {NSReadOnlyPersistentStoreOption : @YES, NSSQLitePragmasOption : @ {@ "journal_mode": @ "DELETE"} };'. - 이제 실제 코드가 어떤 것입니까? –

+0

나는 둘 다 시험했다. – PeterK

+0

SQLite 파일이 앱과 함께 제공된다고 가정합니다. 데이터베이스를 만들 때 * WAL 모드를 비활성화 했습니까? –

답변

4

에 코드

NSSQLitePragmasOption 키를 포함하는 사전에
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:1] 
               forKey:NSReadOnlyPersistentStoreOption]; 
options = @{ NSSQLitePragmasOption : @{@"journal_mode" : @"DELETE"} }; 

세트 options 아니지만 NSReadOnlyPersistentStoreOption 키, 두번째 줄은에 할당 사전을 덮어 쓰기 때문에 첫 번째 줄. 당신은 아마 원하는 것은

NSDictionary *options = @{ 
    NSReadOnlyPersistentStoreOption : @YES, 
    NSSQLitePragmasOption: @{@"journal_mode":@"DELETE"} 
}; 

가 두 키를 포함하는 options 디렉토리를 만드는 것입니다.

을 응용 프로그램과 함께 제공하면 WAL 모드를 비활성화해야합니다.

시뮬레이터에서 응용 프로그램 디렉터리가 읽기 - 쓰기이지만 장치에서 읽기 전용이므로이 문제는 시뮬레이터에서 발생하지 않습니다.

+0

덕분에, 불행히도 이번에는 시뮬레이터에서 같은 오류가 발생했습니다 :-( – PeterK

+0

해결책 인 MartinR의 의견 : SQLite 파일이 앱과 번들되어 있다고 가정합니다. 생성시 WAL 모드를 사용 중지 했습니까? 데이터베이스 - Martin R 2 시간 전 – PeterK

관련 문제