UIWebView file chooser issue in iOS 9

This question is about an iOS app with an integrated UIWebView. I'm using Xcode 7.0. One of the server-loaded pages presented in the UIWebView is a file chooser, similar to:


<form action="post.jsp" id="photo" method='POST' enctype='multipart/form-data'>

<label>Photos:</label>

<input type="file" name="photo1" id="photo1" /><br/>

<input type="file" name="photo2" id="photo2" /><br/>

<button type="submit" role="button" id="fileUpload">Select Photos</button>

</form>


On iOS 8 this works as I'd expect and have seen elsewhere: When tapping the (ugly) file chooser button in the webView, the user is shown their photo library, which sends the selected photo back to the browser.


On iOS 9, this works differently, and eventually fails. When tapping the file chooser button, the user is presented with an action sheet asking them to choose between their Photos Library and iCloud. Tapping either dismisses the action sheet, but the photo library never appears (returns to the prior view). Curiously, I have one user saying they're seeing this same behavior in iOS 8.4.1 but I haven't reproduced this myself in iOS 8.


In Xcode's console I see:


Warning: Attempt to present <UIImagePickerController: 0x7fddfd8d4800> on <CustomNavigationController: 0x7fddfe053400> whose view is not in the window hierarchy!


CustomNavigationController is absolutely the NavigationController for the View Controller containing the webView.


Reveal also shows the Action Sheet in question is presented by the OS in a UIRemoteView, out of band of the application. My concern is the OS may be attempting to display the photo picker before the remote view is gone, thus out of my control to fix.


Any thoughts on this would be much appreciated.

Replies

I am having this same problem, and I also did not see a problem with iOS 8.4 - the camera and photo library both worked fine. But both are broken in iOS 9 with the same error message. Are you using Appcelerator or similar tool to generate your application, or are you working directly with Xcode?

Nice to know I'm not alone!


This is a straight-up Xcode project.

Thanks for posting details of your investigation. I was wondering if you have also filed a radar bug report for the same?


Thanks,


Jesse

I also encountered the same problem, you solve yet?

Yes, that post on stackoverflow introduced some workaround or tricks.


But it seems like a bug of iOS and still not fixed at the time when iOS 10 is coming.

I am facing exact issue. But for me , it was working fine till iOS 9. Only after i updated to iOS 10. Now if select Take picture/Photo library from file chooser, it doesn't work. Anyone got the final resolution

hi, this work for me

add to info.plist :

privacy - Photo Library Usage Description

privacy - Camera Library Usage Description



The problem was in the security of the xcode that does not allow the access to the camera and gallery if you do not specify so that you use them

You have to dismiss the the view by using


override func dismiss(animated flag: Bool, completion: (() -> Void)?)

{

     if self.presentedViewController != nil {

     super.dismiss(animated: flag, completion: completion)

     }

}


You have to use this method in which controller contains your webview. Your problem should be gone but if dose not solved yet and app restart after attaching the file or image. Then probably you are using


viewDidAppear(_ animated: Bool)

Just use viewDidLoad instead of viewDidAppear(_ animated: Bool)