0

I have an app with a Storyboard scene. In the storyboard scene I have a UIWebView. In the storyboard scene I have a UIWebView. My code is as follows:

@IBOutlet weak var webView: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()

    let url = URL(string: “http://www.somepage.com”)
    let urlRquest = URLRequest(url: url!)
    webView.loadRequest(urlRquest)
}

The user is able to navigate and click on links in the UIWebView. I run into an issue when that web view requests access to the camera or stored photos.

iOS presents a standard control at the bottom of the view with the following options: Take Photo or Video Photo Library Browse Cancel

Once the user selects ANY of the options the webview disappears and I get the following error:

<UIImagePickerController: 0x1071ae400> on <MyApp.WebViewVC: 0x10e924ae0> whose view is not in the window hierarchy!

  • I am not able to use WKWebView in this particular app.
  • I have verified that the proper permissions are requested in the plist file and I am able to access photo album and camera within the app and have requested permissions before calling the web view.
  • I did not implement any of the UIImagePickerControllerDelegate functions as this is a UIWebView requesting access.
xdeleon
  • 769
  • 8
  • 20
  • Found my answer here after further research: https://stackoverflow.com/questions/25942676/ios-8-sdk-modal-uiwebview-and-camera-image-picker/26238123#26238123 – xdeleon Nov 20 '18 at 23:02
  • suspicious point i am not able to use WKWebview for this app. what issue did you face ? for your problem best solution is wkwebview. – Muhammad Shauket Nov 21 '18 at 03:36
  • My app needs to support iOS 10-12. I also need to access the cookies of the embedded browser/view. WKWebView did not implement support for cookie access until iOS 11 as noted here: https://stackoverflow.com/questions/33156567/getting-all-cookies-from-wkwebview . With UIWebView I can access cookies as documented here: https://stackoverflow.com/questions/771498/where-are-an-uiwebviews-cookies-stored . While I agree it’s preferable to use WKWebViewI noted that I can’t use it “in this particular app” but did not put the particulars as I was trying to keep my question specific. – xdeleon Nov 21 '18 at 19:16
  • There is way to sync cookies i am using wkwebview and syncing cookies till ios 8 – Muhammad Shauket Nov 22 '18 at 01:26
  • as for your issue, can you read this doc they have fix for this error. https://pinkstone.co.uk/how-to-avoid-whose-view-is-not-in-the-window-hierarchy-error-when-presenting-a-uiviewcontroller/ – Muhammad Shauket Nov 22 '18 at 01:59

0 Answers0