나는 사용자가 iOS 장치에서 이메일을 통해 sqlite 데이터베이스를 백업 및 복원하도록합니다. 나는 수출하고 sqlite 데이타베이스를 성공적으로 수입한다. 내 문제는 현재 sqlite 파일을 데이터가 자동으로 업데이트되지 않는 새 파일로 대체하려고 할 때입니다. 함수의 끝에 exit (0)을 추가하면 앱이 닫히고 데이터가 닫힙니다. 이는 기본적으로 충돌이므로 해결 방법이 아닙니다. 여기에 하나의 sqlite 파일을 다른 것으로 대체하는 데 사용하는 함수가 있습니다. 참고 전체 데이터베이스가 하나의 sqlite 파일이되도록 저널링을 해제했습니다. 응용 프로그램이 실행되는 동안 다른 사람과 sqlite 파일을 바꿀 올바른 방법을 아는 사람이 있습니까? 고맙습니다.응용 프로그램이 실행되는 동안 핵심 데이터 sqlite 파일을 전환 하시겠습니까? 데이터가 표시되지 않습니다
- (BOOL)resetApplicationModel {
// ----------------------
// This method removes all traces of the Core Data store and then resets the application defaults
// ----------------------
NSError *_error = nil;
NSURL *_storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Database.sqlite"];
NSPersistentStore *_store = [persistentStoreCoordinator persistentStoreForURL:_storeURL];
// Remove the SQL store and the file associated with it
if ([persistentStoreCoordinator removePersistentStore:_store error:&_error]){
[[NSFileManager defaultManager] removeItemAtPath:_storeURL.path error:&_error];
}
if (_error) {
NSLog(@"Failed to remove persistent store: %@", [_error localizedDescription]);
return NO;
}
[persistentStoreCoordinator release], persistentStoreCoordinator = nil;
[managedObjectContext release], managedObjectContext = nil;
NSString *applicationDocumentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *originalFile = [applicationDocumentDirectory stringByAppendingPathComponent:@"Database.sqlite"];
NSString *backupDatabaseFolder = [applicationDocumentDirectory stringByAppendingPathComponent:@"Backups"];
NSString *backupFile = [backupDatabaseFolder stringByAppendingPathComponent:[NSString stringWithFormat:@"DatabaseBackup.sqlite"]];
[[NSFileManager defaultManager] copyItemAtPath:backupFile toPath:originalFile error:nil];
// Rebuild the application's managed object context
rootViewController.managedObjectContext = nil;
rootViewController.managedObjectContext = self.managedObjectContext;
return YES;
}
이렇게하면 앱이 새 데이터를 어딘가에로드합니까? –
함수의 끝에 exit (0)를 추가하면 시뮬레이터에서 테스트 할 때 새 데이터가 나타납니다. 앱을 처음 시도 할 때 앱에 메모리가 없으면 앱도 작동합니다. 앱이 메모리에있는 경우 작동하지 않습니다. 메모리에서 앱을 제거한 후 다시 열어도 새 데이터가 표시되지 않습니다. 감사. – d264789
질문에 답변하지 않았습니다. 이 코드를 실행하면 앱이 새 영구 저장소에서 데이터를로드하려고합니까? –