My App has one ViewController
, one UIWebView
and 4 UIImageView
The control flow in my app:
-> Capture a Image from camera and store into UIImage
variable, this happens in didFinishPickingMediaWithInfo
function. Do some processing on the Image.
-> From didFinishPickingMediaWithInfo
function, load UIWebView
with an inline html/css code i.e.
webview.hidden = false
WebView.loadHTMLString(htmlString, baseURL: nil)
-> After the above html is loaded into UIWebView, delegate function webViewDidFinishLoad is called. From webViewDidFinishLoad, take a snapshot of whatever is loaded in UIWebView into a Image with the code below:
var image:UIImage?
autoreleasepool{
UIGraphicsBeginImageContextWithOptions(WebView.frame.size, false, 1.0)
WebView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
}
-> Store the captured image into a UIImage variable.
-> Load one more different html/css code into the same UIWebView ( I am still in the webViewDidFinishLoad function): the html loading code is same as above i.e.
WebView.loadHTMLString(htmlString1, baseURL: nil)
-> webViewDidFinishLoad is called again because of new html code loaded in above step, and I do the same thing i.e. take a snapshot of the UIWebView content into UIImage variable and load new html pattern
-> I do this 4 times i.e. in the end I have 4 Images captured in 4 UIImage variables. I load all these 4 images into the 4 UIImageView on my storyboard.
-> Then I dismiss imagepicker
imagePicker.dismissViewControllerAnimated(true, completion: nil)
Here is the issue I am seeing in the end:
-> Sometimes, Image1 is same as Image 2, and sometimes all Images are the same. This happens randomly. I know for sure that all these 4 images should be unique. Because I load different html code in each step.
- What Am I doing wrong in the sequence above?