0

I have fetched UIImage from photos library in ipad using UIImagePickerController. Now I want to save that image in a directory that is associated with my app and contains already added images. I have also got the url of the directory.

For example : file://localhost/Users/administrator/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/31816EF9-AE1E-40DF-93C4-C67A82E4B85B/Documents/7884/Images/

How can I save uiimage in the specified directory?

2
  • you want to save the image in your mac or in iphone? That url is for simulator... please clear. Commented Jan 9, 2013 at 12:09
  • This url is for simulator but I also want the same functionality on ipad. Commented Jan 9, 2013 at 12:15

1 Answer 1

1

Use this code to save it into your Document Directory.

NSData *pngData = UIImagePNGRepresentation(image);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
NSString *documentsPath = [paths objectAtIndex:0]; 
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.png"]; 
[pngData writeToFile:filePath atomically:YES]; 
2
  • Thanks a lot for the help but problem still exists. It is saving in the documents directory but does not save image in the intended sub directory specified in the above url Commented Jan 9, 2013 at 12:33
  • 1
    first you need to check if any directory is not there then create it, then save. Commented Jan 9, 2013 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.