1

I have implemented the logic of writing files into document directory.

NSData *pngData = UIImagePNGRepresentation([UIImage imageNamed:@"logo_icon_login.png"]);

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.png"];

if ([[NSFileManager defaultManager] isWritableFileAtPath:filePath])
{
  [pngData writeToFile:filePath atomically:YES];
}
else
{
  NSLog(@"Not writable.");
}

Now the problem is in some devices it says Not writable. Is there any permission should I need before writing files in the documents directory?

Poles
  • 3,585
  • 9
  • 43
  • 91
  • 1
    refer to this: http://stackoverflow.com/questions/11053842/how-to-save-file-in-the-documents-folder – dokun1 Feb 11 '16 at 06:48

1 Answers1

0

Create a folder namely images and than put the image inside. It could be root directory issue.

Try this:

NSString *filePath = [documentsPath stringByAppendingPathComponent:@"images/image.png"];
TechBee
  • 1,897
  • 4
  • 22
  • 46
  • The root directory for documents is writable by default if your data is formatted correctly. See my comment above, as this questions seems to reference an issue that has already been answered. – dokun1 Feb 11 '16 at 07:01