How to hide folders created in the document directory in ios?

I created PDF program files that are stored in the device 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 Document Document folder.

I want to hide these files so that the user cannot see or delete them.

Can anyone help me do this.

+6
source share
2 answers

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 create a path to this folder using:

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

You will need to create a folder yourself on first use, 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 for NSFileManager: https://github.com/nicklockwood/StandardPaths

+12
source

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

But the real solution is to not store the document in NSDocumentDirectory in the first place. You must create a subdirectory in NSLibraryDirectory and save this stuff there. It also gets a backup and will not be cleared like Caches and tmp , but the user cannot access it using iTunes.

+3
source

Source: https://habr.com/ru/post/908017/


All Articles