Data Saved in document Directory Dissappearing

57 Views Asked by At

My app stored downloaded audios and videos in document directory.Some users of app facing the problem that the content downloaded on their device getting disappeared with out any specific reason i.e app update. To save a file my path is as follows.

NSArray *dirPaths;
NSString *docsDir;

dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                               NSUserDomainMask, YES);
docsDir = dirPaths[0];

NSString *filepath = [NSString stringWithFormat:@"%@/%@_%@_%@", docsDir,username,audioId,fileName];

 [[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];

The username , audioID and fileName in my app never change. So only option left is that somehow the path of my document directory is changing at the time when app try to search for the saved files, as described in Apple Doc. So i just want to know if i am thinking in the write direction or there is some other reason behind disappearing of content?

1

There are 1 best solutions below

0
Sanjan Piya On

create your docs dir as below:

NSString * docsDir = [[dirPaths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@_%@", username, audioId, fileName]];