먼저 데이터베이스를 생성하고 .sqlite 확장자를 제거하십시오. 그런 다음이 db를 xCode의 Resources 디렉토리로 드래그하고 다음을 수행하십시오.
파일 상자 추가 옵션을 선택하십시오. 체크 박스에 '필요한 경우 대상 그룹의 폴더에 항목 복사'가 표시되고 완료됩니다.
당신은 자원 디렉토리의 하위 목록으로 데이터베이스 파일을 볼 수
나는 지금 위치
에이 데이터베이스 파일을 복사 할 수있는 링크를 따라 여기
을 이미지를 게시 할 수있는 충분한 명성이 없어 죄송합니다
How to copy sqlite database when application is launched in iOS?
나는 AppDelegate.m
에서 마지막 줄에서 @end 앞에 다음 코드를 사용
- (void) copyDatabaseIfNeeded{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
_dbPath = [self getDBPath];
BOOL success = [fileManager fileExistsAtPath:_dbPath];
if(!success){
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"data_items"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:_dbPath error:&error];
if (!success)
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}}
/********* Database Path *********/
- (NSString *) getDBPath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"data_items"];
}
그리고 그것의 코드
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
후 라인
[self copyDatabaseIfNeeded];
를 복사합니다. 코드 사용
function onDeviceReady() {
var db = window.sqlitePlugin.openDatabase("data_items", "1.0", "data_items", 200000);
...
}
복사 된 위치에서 직접 데이터베이스를 편집 할 수도 있습니다. 다음 링크 사용
Where does the iPhone Simulator store its data?
출처
2013-12-02 12:37:56
Avi