0

I am trying to display a photograph captured by a user using UIImagePickerController in a webView. The only logical solution I could think of was to capture the file path and include this in the HTML. I have achieved this but the image is not showing, I am simply getting a white box with the alt text showing.

Is there a solution to get this working?

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {

    if cameraBool {

        let imageData = UIImageJPEGRepresentation(image, 0.6)
        let compressedJPGImage = UIImage(data: imageData!)

        ALAssetsLibrary().writeImageToSavedPhotosAlbum(compressedJPGImage!.CGImage, orientation: ALAssetOrientation(rawValue: compressedJPGImage!.imageOrientation.rawValue)!,
            completionBlock:{ (path:NSURL!, error:NSError!) -> Void in

                //capture file path as string
                self.pathString = String(path)
                //Insert path as HTML URL
                self.texttemp = "hello <img src=\"\(self.pathString)\" alt=\"user photo\" height=\"500\" width=\"300\"/>"
                //Load HTML into webView
                self.myWebView.loadHTMLString(self.texttemp, baseURL: self.baseURL)

                print(self.texttemp) //Prints hello <img src="assets-library://asset/asset.JPG?id=78A82D22-7115-4C9B-B31F-8C8A57123AE7&ext=JPG" alt="user photo" height="500" width="300"/>
        })
    }

    self.dismissViewControllerAnimated(true, completion: nil);
}
Ben Sullivan
  • 2,134
  • 1
  • 18
  • 32

0 Answers0