iOS 8 SDK: modal UIWebView and camera/image picker
I found that in iOS 8.0.2 iPad does not seem to have that bug but iPhone still does.
However, overriding following in the view controller containing the uiwebview
-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
And checking that there is a presentedViewController seems to work.
But need to check side effects
#import "UiWebViewVC.h"@interface UiWebViewVC ()@property (weak, nonatomic) IBOutlet UIWebView *uiwebview;@end@implementation UiWebViewVC- (void)viewDidLoad{ [super viewDidLoad]; NSURL *url = [NSURL URLWithString:@"http://html5demos.com/file-api-simple"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; self.uiwebview.scalesPageToFit = YES; [self.uiwebview loadRequest:request];}-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion{ if ( self.presentedViewController) { [super dismissViewControllerAnimated:flag completion:completion]; }}@end
I have the same issue on iOS 9. Try to add ivar '_flag' and then override this methods in view controller with UIWebView
#pragma mark - Avoiding iOS bug- (UIViewController *)presentingViewController { // Avoiding iOS bug. UIWebView with file input doesn't work in modal view controller if (_flagged) { return nil; } else { return [super presentingViewController]; }}- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion { // Avoiding iOS bug. UIWebView with file input doesn't work in modal view controller if ([viewControllerToPresent isKindOfClass:[UIDocumentMenuViewController class]] ||[viewControllerToPresent isKindOfClass:[UIImagePickerController class]]) { _flagged = YES; } [super presentViewController:viewControllerToPresent animated:flag completion:completion];}- (void)trueDismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion { // Avoiding iOS bug. UIWebView with file input doesn't work in modal view controller _flagged = NO; [self dismissViewControllerAnimated:flag completion:completion];}
This works for me fine
For me I tend to have a custom UINavigationController so that multiple views can share the same logic. So for my workaround (in Swift) here is what I put in my custom NavigationController.
import UIKitclass NavigationController: UINavigationController { override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } override func dismissViewControllerAnimated(flag: Bool, completion: (() -> Void)?) { if let vc = self.presentedViewController { // don't bother dismissing if the view controller being presented is a doc/image picker if !vc.isKindOfClass(UIDocumentMenuViewController) || !vc.isKindOfClass(UIImagePickerController) { super.dismissViewControllerAnimated(flag, completion:completion) } } } override func viewDidLoad() { super.viewDidLoad() // make sure that the navigation controller can't be dismissed self.view.window?.rootViewController = self }}
This means that you can have loads of view controllers with webviews and they'll all work with the file upload element.