これが私のコードです。以下を参照してください。
-(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.
編集: ImagePicker をピックしている間、パスを作成する必要があります。以下の ImagePickerViewControllerDelegate.i のデリゲートを参照してください。
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
}
参考になれば幸いです...!!!!