2011-12-08 59 views
3

我正在使用SQLite數據庫製作ipad應用程序。如何隱藏文件夾中的特定文件。

我希望能夠從iTunes中添加.sqlite文件來自由添加數據庫文件並返回user_data。

所以,我必須將文件保存在/ Documents文件夾中。

然後,我有一個問題。

我不想在iTunes中顯示某些數據庫文件。 - (例如,像用戶備忘錄數據庫)

我該怎麼辦?

+0

看看這個問題,http://stackoverflow.com/questions/2942855/iphone-documents-directory-and-uifilesharingenabled-hiding-certain-documents –

回答

2

如果您不希望顯示的數據用戶可以使用下面的文件夾,並從那裏使用存儲

相同的位置訪問數據庫//要訪問您的iOS設備

的ApplicationSupport文件夾
NSString *appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject]; 

//訪問應用程序的庫文件夾中(即Application/APPID /庫)

NSString *libraryDir = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject]; 

從一個文件夾移動到另一個數據使用下面的代碼:

NSFileManager *mngr = [[NSFileManager alloc] init]; 

NSString *ExpectedFilePath=[[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Filename.ext"]; 

//getting Document directory path 
NSString *FilePresentAtPath=[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Filename.ext"]; 

// If the database doesn't exist in our Document folder we copy it to Library (this will be executed only one time). 
if (![mngr fileExistsAtPath:ExpectedFilePath]) 
{ 
    [mngr moveItemAtPath:FilePresentAtPath toPath:ExpectedFilePath error:NULL]; 
} 
[mngr release];