1

In my iPhone app I am downloading some binary files. I want to store these files in a local folder in the device. And also I want to make these files as Read-only/Hidden. Is it possible? So that I can give more security for the files. Is there any way to implement the this? Please give me some good explanations also some code samples. Thanks

Mithuzz
  • 1,091
  • 14
  • 43

3 Answers3

2

All the files that you create in your app will be only accessible by your app.

but you can set it to immutable, I do not know how it will help you.

NSDictionary* att = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSNumber numberWithBool:YES], nil] forKeys:[NSArray arrayWithObjects:@"NSFileImmutable", nil]];
[filemgr createDirectoryAtPath:@"YourPath" withIntermediateDirectories:YES attributes:nil error:nil];
[filemgr createFileAtPath:@"YourPath/yourFile.txt" contents:data attributes:att];
ggrana
  • 2,335
  • 2
  • 21
  • 31
1

You can set POSIX permissions on files using NSFileManager, using the method:

- (BOOL)setAttributes:(NSDictionary *)attributes ofItemAtPath:(NSString *)path error:(NSError **)error

I am not sure how much security this actually gives you though. Each iOS application has its own sandbox, the only application that can touch your files apart from the system, is yours. So you are only protecting the file from yourself.

Tark
  • 5,153
  • 3
  • 24
  • 23
  • I just wanted to block the user if the user try to access the files through the system. By opening the root folder. – Mithuzz Mar 23 '12 at 11:09
  • 2
    What system? The user is the owner of all application files on the device, you cannot stop the user accessing their own files. – Tark Mar 23 '12 at 11:15
  • I agree, I am not sure, that's why I am asking again. I just wanted to know that whether it is possible to set a file read-only or hidden in a device, So that it will not be accessible or will be hidden, and the files can be accessed only through the app. I am sorry if I am saying any foolishness, because I am not familiar with this area. And thanks for your reply. – Mithuzz Mar 23 '12 at 11:24
1
+(BOOL)saveFile2DocDirectory:(NSData*)recievedData:(NSString*)moduleNam   {

NSString *location=[NSString stringWithFormat:@"%@",moduleNam];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fPath = [documentsDirectory stringByAppendingPathComponent:location];

//NSMutableDictionary *courseInfoDict=[[NSMutableDictionary alloc]init];


return [recievedData writeToFile:fPath options:NSDataWritingFileProtectionComplete error:nil];


}

//This function will help you out.

Kuldeep
  • 2,589
  • 1
  • 18
  • 28
  • here how can I set the file as read-only? (or hidden if its possible) – Mithuzz Mar 23 '12 at 11:25
  • 1
    @John http://stackoverflow.com/questions/7471270/secure-contents-in-document-directory Go through the link you will be clear all about the security of stored file – Kuldeep Mar 23 '12 at 11:36