2012-08-07 2 views
5

나는 애플의 데이터 스토리지 가이드 라인을 읽었으며 정말로 내 앱에서 생성하고있는 sqlite 데이터베이스 파일을 어디에 보관해야하는지 혼란 스럽다. 응용 프로그램이 Offfline 모드 일 때도 sqlite 파일에서 읽으려고합니다. 나는 그런 파일들이 "do not backup"플래그가 설정된 라이브러리/캐시에 보관되어야한다고 읽었습니다. 같은 일을하는 올바른 방법을 제시해주십시오.sqlite 데이터베이스 파일을 Documents 디렉토리 또는 Library/Caches에 써야합니까?

답변

5

대답은 데이터베이스 파일을 생성하는 방법에 따라 달라집니다

According to the Data Storage Guidelines page : 사용자 생성, 또는 그 다른 응용 프로그램에서 재현 할 수없는

  1. 만 문서 및 기타 데이터/Documents 디렉토리 에 저장해야하며 iCloud에서 자동으로 을 백업합니다.

  2. 다시 다운로드하거나 다시 생성 할 수있는 데이터는/Library/Caches 디렉터리에 저장해야합니다. 캐시 디렉토리에 넣어야하는 파일의 예는 데이터베이스 캐시 파일 과 잡지, 신문, 및지도 응용 프로그램에서 사용되는 것과 같은 다운로드 가능한 내용을 포함해야합니다.

이 나에게 상대적으로 분명한 것 같다 앱 프로그래밍 방식으로 뭔가를 만들거나 당신이 저장하려는 데이터를 생성하는 경우, 그것은 "캐시"폴더에 넣어. 고객이 직접 생성 한 고유 한 항목 (키보드 나 직접 입력 한 항목을 통해 입력 한 경우)을 "문서"에 넣습니다.

은 "수행은 백업되지 않음"파일 결코가 iCloud에 최대 전송받을 것을 의미하고이 길을 잃을 경우, 그들은 처음부터 다시 만들어야 (또는 다시 설치하십시오)이있다.

+0

전 완전히 정적 인 앱을 개발했습니다. 나는 4MB 이상의 크기로 데이터를 저장하고있다. 이 콘텐츠가 없으면 앱이 작동하지 않습니다. 내 경우에는 어디에서 로컬 데이터베이스 (문서 폴더 또는 라이브러리 폴더)를 저장해야합니까? – Warrior

+0

[글쎄, 당신은 이미 이것을 별도의 질문으로 보았습니다.] (http://stackoverflow.com/questions/16767861/where-to- save-the-local-db-created-for-iphone-app), 그래서 나 (또는 ​​다른 누군가)가 당신을 위해 답을 찾아 볼 것입니다. –

+0

새로운 확장 기능과 감시 기능은 어떻습니까? –

1

이 정보는 도움이 될 수 있습니다. 문서 디렉토리에 데이터베이스를 복사하는 것만으로도 충분합니다. 번들에있는 파일은 읽기 전용입니다. 일부 상황에서는 언제든지 문서 디렉토리에 데이터베이스가없는 경우 데이터베이스를 복사하는 것이 더 좋습니다.

디렉토리는 문서로 데이터베이스를 복사하는 샘플 코드는 다음과 같습니다

-(void) checkAndCreateDatabase { 

    // Setup some globals 
    NSString *databaseName = @"AnimalDatabase.sql"; 

    // Get the path to the documents directory and append the databaseName 
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDir = [documentPaths objectAtIndex:0]; 
    NSString *databasePath = [documentsDir stringByAppendingPathComponent:databaseName]; 


    // Check if the SQL database has already been saved to the users phone, if not then copy it over 
    BOOL success; 

    // Create a FileManager object, we will use this to check the status 
    // of the database and to copy it over if required 
    NSFileManager *fileManager = [NSFileManager defaultManager]; 

    // Check if the database has already been created in the users filesystem 
    success = [fileManager fileExistsAtPath:databasePath]; 

    // If the database already exists then return without doing anything 
    if(success) return; 

    // If not then proceed to copy the database from the application to the users filesystem 

    // Get the path to the database in the application package 
    NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; 

    // Copy the database from the package to the users filesystem 
    [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; 

    [fileManager release]; 
} 

당신이 Tutorial 파일을 참조 할 수 있습니다, 문서의 내용이 디렉토리는 사용자가 내용을 읽을 수 있도록, 쓰기 모드, 읽기 데이터베이스에서.

관련 문제