How do i load an image from the IOS photo library to a UIWebView?

1.1k views Asked by At

i have this code in my program but it seems to be crashing the program and i cant figure out why.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    //Get Image URL from Library
    NSURL *urlPath = [info valueForKey:UIImagePickerControllerMediaURL];
    NSString *urlString = [urlPath absoluteString];
    NSLog(urlString);

    NSURL *root = [[NSBundle mainBundle] bundleURL];
    NSString *html;
    html = @"<img src='";
    html = [html stringByAppendingString:urlString];
    html = [html stringByAppendingString:@"' />"];
    [MemeCanvas loadHTMLString:html baseURL:root];

    [picker dismissViewControllerAnimated:YES completion:^{}];

}

It seems to be caused around the section where i append the asset-library address (urlString) to the the html string. i dont know why this would give a problem.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString stringByAppendingString:]: nil argument'

Any help is appreciated.

Thanks in advance.

2

There are 2 answers

4
Craig Moore On BEST ANSWER

Does this link help? It explains that you will not get a URL for images but an image object instead.

UIImagePickerControllerMediaURL always nil for a photo

2
Diptesh On

I guess you need to save the image in documents directory and then display it in the webview.