Droidme
Droidme

Reputation: 1252

saving images to resources folder in iphone

i am downloading images from the server i would like to know whether it is possible to save those images to the resources folder of the project...if it is possible please someone explain me. Thank you

Upvotes: 2

Views: 1518

Answers (2)

Baby Groot
Baby Groot

Reputation: 4279

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
             NSString *documentsDirectory = [paths objectAtIndex:0];
             NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"MD%d.png",y]];
             UIImage *image = imgProfile; // imgProfile is the image which you are fetching from url
             NSData *imageData = UIImagePNGRepresentation(image);
             [imageData writeToFile:savedImagePath atomically:NO]; 

Upvotes: 1

Amit Singh
Amit Singh

Reputation: 8383

yes you can do that but resource folder is call Document Directory in iPhone and you can save anything that you want and almost all abstract data types have a method to do that name writeToFileAtPath:atomically:. // note atomically, not automatically`

You just need to pass the path of file where you want to save it.

As far as path of Document Directory is concerned its like this

[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

this returns the path of Document Directory

Upvotes: 2

Related Questions