Вопрос

Here is what I need.

I need my users to be able to pick an image from the photo library, however, they should not need to have to repick it each time they use it. Instead, I would like to remember the photo's path to be able to load it in the future. Is this possible? If not, what are the alternatives? Is it possible to cache the photo to a local folder or place?

Thanks

Это было полезно?

Решение

You can't keep an reference to the picked image, so you need to, as you suggest your self, save a local copy of the image. You could use the UIImagePicker to let the user pick the image and then save it locally:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   UIImage* image = (UIImage*) [info objectForKey:UIImagePickerControllerOriginalImage];
   NSData *imageData = UIImagePNGRepresentation(image);

 //save the imageData to document dir. You could also save it to the cache...
   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   NSString *documents = [paths objectAtIndex:0];
   NSString *finalPath = [documents stringByAppendingPathComponent:@"myImageName.png"];
   [imageData writeToFile:finalPath atomically:YES];
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top