Take the 2-minute tour ×

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];

    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.

share|improve this question
why? normal user won't be able to see them anyway –  Bryan Chen Feb 9 '12 at 8:29
Maybe they mean from within iTunes? –  twilson Feb 9 '12 at 8:31
Yeah, if you set the document sharing flag in the info.plist, users can see any files in the Documents folder in iTunes. Generally you shouldn't store private data files in Documents, that should only be used for user documents (see below for alternative locations to store application data). –  Nick Lockwood Feb 9 '12 at 9:20
add comment

2 Answers

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.

share|improve this answer
add comment

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) lastObject];

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

if (![self fileExistsAtPath:appSupportDir])
    [self 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

share|improve this answer
+1, useful category (and nicely documented). One request, though: it would be nice if you added comments in the header file as well about what each method does. If someone adds your category to his project and his colleague sees it he might not know what the methods are supposed to return or do. –  DarkDust Feb 9 '12 at 9:14
Valid point. I generally like to leave my header files uncluttered if possible, and there is a link to the github documentation in the .h file, but I can see an argument for putting docs in the header. –  Nick Lockwood Feb 9 '12 at 9:21
add comment

Your Answer


