i’m developing an app in objective-c for iphone. My problem is that my application must save an image taken from a url. The folder is read only i think.. This is my code to save image:
-(void)banner:(NSString *)path{
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: path]];
UIImage *image = [UIImage imageWithData: imageData];
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
NSString* pathEnd = [resourcePath stringByAppendingFormat:@"/banner.png"];
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
NSError *writeError = nil;
[data1 writeToFile:pathEnd options:NSDataWritingAtomic error:&writeError];
}
but when i retrieve image, it isn’t in that folder. what can i do?
You can’t, the application bundle is readonly. You should save any data in either the document or cache directory.
Is there any reason to convert the data an image first and back to an
NSDataobject again?If not you could just do this: