Here is my code see Below.
-(void)copyImagesToCache:(NSString*)imageURl
{
NSFileManager *filemanager=[NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"MyIMages"];
//now no need to use below single line of code.
//NSString *srcPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"image.png"];
//it just a example here , here you should make a source path as you pic the images form the camera.
EDIT:While Taking pick in ImagePicker you should make a path . see below delegate of ImagePickerViewControllerDelegate.i have shown the way
if(![filemanager contentsOfDirectoryAtPath:folderPath error:nil]){
[filemanager createDirectoryAtPath:folderPath withIntermediateDirectories:YES attributes:nil error:nil];
}
NSString *destPath = [folderPath stringByAppendingPathComponent:@"image1.png"];//here you should create the dynamic name so that you can distinguish all images.
NSError *err;
BOOL isCopeid= [filemanager copyItemAtPath:srcPath toPath:destPath error:&err];
if(isCopeid)
NSLog(@"Copied");
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage: (UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
myIMage.image = image;
//here call the method whcih copy the image to cache
[self copyImagesToCache: [editingInfo objectForKey:UIImagePickerControllerReferenceURL]]];
[here is the link which shown the editingInfo's keys ][1]
//remaining code goes here as it is
}
I hope it may help you...!!!!