상점을 제거하고 대신 기본 버전을 복사하여 CoreData DB 재설정을 시도하고 있습니다. 다음은 시뮬레이터에서 잘 작동하지만, iOS 3.1.3 및 3.2.1을 사용하여 테스트하는 장치에서 실행될 때 앱은 앱이 다시 시작될 때까지 데이터베이스가 재설정되지 않는 것처럼 동작합니다. 다시 시작한 후 새로 초기화 된 데이터베이스가 사용되며 모든 것이 정상입니다. 새 저장소에 대한 알림이 필요한 백그라운드 캐시가 있습니까?CoreData 재설정은 기기가 아닌 시뮬레이터에서 작동합니다 (앱 재시작까지)
[아래에서 오류 검사를하고 있습니다. 명확하게하기 위해 해당 행을 삭제하고 있습니다. 물론, 오류가 발생하는하지 않습니다]
-(void)initializeUserData {
NSError *error = nil;
NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"db.sqlite"];
NSURL *storeURL = [NSURL fileURLWithPath:storePath];
[self.managedObjectContext lock];
[self.managedObjectContext reset];
NSPersistentStore *store = [persistentStoreCoordinator persistentStoreForURL:storeURL];
[persistentStoreCoordinator removePersistentStore:store error:&error];
[[NSFileManager defaultManager] removeItemAtPath:storePath error:&error];
// copy the pre-populated database file
NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"db" ofType:@"sqlite"];
[[NSFileManager defaultManager] copyItemAtPath:defaultStorePath toPath:storePath error:&error];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
nil];
[persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error];
[self.managedObjectContext unlock];
}
편집 : 이 무엇을 의미하지만 전성 검사로 내가 -com.apple.CoreData.SQLDebug 켜져 있고하여 후 기록 다음받을 경우 확실하지 않음 addPersistentStoreWithType에 전화 :
CoreData: annotation: Connecting to sqlite database file at "..."
의 I는 removePersistentStore 호출 : 메인 루프에 응용 프로그램을 반환 한 후에 기록됩니다에 와서 기대하는 (다음
CoreData: annotation: Disconnecting from sqlite database.
데이터베이스에 액세스하고 있음에도 불구하고 "데이터베이스에 연결 중"메시지가 나중에 표시되지 않으므로 이러한 로그 항목의 홀수 순서는 로깅이 수행되는 방식의 부작용이라고 가정합니다. ..
아, 전화하세요. 불행히도 그것은 문제가되지 않습니다. 두 줄에 BOOL 캐치를 추가하고 (좋은 측정을 위해 copyItemAtPath :), 그 중 아무 것도 실패하고 있습니다. 나는 정말로 스레딩을 사용하지 않고 잠금/잠금 해제 선은 내가 알지 못하는 이상한 것을 고칠 수 있는지 디버깅하는 동안 추가 한 "경우에 따라"행뿐입니다. 죄송합니다. 게시하기 전에 삭제해야합니다. 죄송합니다. 새로운 소식입니다. 스택을 처음부터 다시 빌드하는 것은 ManagedObjectContext와 PersistentStoreCoordinator를 해제하고 객체를 다시 만드는 것을 의미할까요? – Tony
OK, 예, 알아 냈습니다. 당신 말이 맞아요. 모든 것을 핵으로 만들고 처음부터 다시 시작하는 것이 가장 좋습니다. =) – Tony