How to hide folders created in Document Directory in ios?

南笙酒味 提交于 2019-12-29 06:55:07

问题


I have created some PDF files programatically, which i am storing into the devices memory using the following code >>>>

    NSString *fileName = [NSString stringWithFormat:@"SampleTextFile.pdf",strFinalString];

    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *saveDirectory = [path objectAtIndex:0];
    NSString *saveFileName = fileName;
    NSString *documentPath = [saveDirectory stringByAppendingPathComponent:saveFileName];

I can see the file in the Devices Document folder.

I want to hide these files so that the user can not see or delete it.

Can anyone help me out to do this.


回答1:


A good place to store private data is in ~/Library/Application Support/, which is the folder used on the Mac for this purpose.

You can generate a path to this folder using:

NSString *appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) firstObject];

You'll have to create the folder yourself the first time you use it, which you can do with:

if (![[NSFileManager defaultManager] fileExistsAtPath:appSupportDir])
{
    [[NSFileManager defaultManager] createDirectoryAtPath:appSupportDir withIntermediateDirectories:YES attributes:nil error:NULL];
}

I wrote a simple library that makes this and all other useful iOS folders available as methods on NSFileManager: https://github.com/nicklockwood/StandardPaths




回答2:


Just prefix the filename with a dot, as in .SampleTextFile.pdf.

But the real solution is to not store the document in the NSDocumentDirectory in the first place. You should create subdirectory in the NSLibraryDirectory and store this stuff there. It also gets backed up and will not get purged like Caches and tmp, but the user cannot access it with iTunes.



来源:https://stackoverflow.com/questions/9207495/how-to-hide-folders-created-in-document-directory-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!