많은 설명과 스택을 찾았지만 지금까지는 도움이되지 않았습니다.코어 데이터가 시뮬레이터에 채워지지만 장치로 이동하지 않습니다.
꽤 많이 myapp.sqlite (미리 채워진 myapp.sqlite)는 시뮬레이터에서 제대로 작동하지만 iPad에서 실행할 때 비어 있습니다.
- 내가 번들로 SQLite는 DB를 복사 할 수 있지만 내가 라이브러리 폴더로 이동 :
그래서 다른 일을 시도 후, 이것은 내가 가진 가장 가까운 것입니다. 내 AppDelegate에에
내가 이렇게 :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"Starting to save the DB to another location");
NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
NSString *targetPath = [libraryPath stringByAppendingPathComponent:@"myDB.sqlite"];
if (![[NSFileManager defaultManager] fileExistsAtPath:targetPath]) {
// database doesn't exist in your library path... copy it from the bundle
NSString *sourcePath = [[NSBundle mainBundle] pathForResource:@"myDB" ofType:@"sqlite"];
NSError *error = nil;
if (![[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:targetPath error:&error]) {
NSLog(@"Error: %@", error);
}
}
return YES;
}
을 다음 PersistentStoreCoordinator에, 나는 DB, (fetchRequest)를 사용하려고 할 때 나는이
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
NSString *targetPath = [libraryPath stringByAppendingPathComponent:@"myDB.sqlite"];
// NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"naccApp.sqlite"];
// NSURL *storeURLLocal = [[NSBundle mainBundle] URLForResource:@"myDB" withExtension:@"sqlite"];
NSURL *storeURL = [NSURL URLWithString:targetPath];
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
}
을, 나는 얻을 오류 :
CoreData SQL 저장소는 파일 URL 만 지원합니다 (/var/mobile/Applications/2EB2AADD-DF9D-475F-A05E-BB138502471F/Library/myDB.sqlite).
메시지는 분명하지만 여기 거의 모든 도움을 시도했지만 아직 아무 것도 시도하지 않았습니다.
필자는 Core Data를 처음 사용하기 때문에 무지를 용서해주십시오.
아,
Worked ... finally! 그 점을 발견해 주셔서 감사합니다. – Elkucho