I have found that, when compiling for iOS 8 (and running in iOS 8), a UIWebView
cannot show the camera/image picker if the UIWebView
is in a view controller presented modally. It works without problem in view controllers directly “hanging” from the window rootViewController
or view controllers pushed from it.
The test application can be found at https://dl.dropboxusercontent.com/u/6214425/TestModalWebCamera.zip but I will describe it below.
My test application (built with storyboards, but the real application doesn’t use them) has two view controllers (unoriginally named ViewController
and ViewController2
). ViewController
is contained in a UINavigationController
which is the root view controller. ViewController
contains a UIWebView
(works OK), a button that “shows” (“pushes”) ViewController2
, and a UIBarButtonItem
which modally presents ViewController2
. ViewController2
has another UIWebView
which works when “pushed” but not when “presented”.
Both ViewController
and ViewController2
are loaded with:
- (void)viewDidLoad { [super viewDidLoad]; [self.webView loadHTMLString:@"<input type=\"file\" accept=\"image/*;capture=camera\">" baseURL:nil]; }
When trying to use the modal UIWebView
Xcode prints the following in the console and dismisses the app modal:
Warning: Attempt to present <UIImagePickerController: 0x150ab800> on <ViewController2: 0x14623580> whose view is not in the window hierarchy!
My current theory is that the changes in UIActionSheet
to UIAlertController
might have produced this situation, but it’s quite hard to prove. I will open a Radar with Apple, just in case.
Has someone found the same situation and some workaround?
Starting with version 0.8.2 of the image_picker plugin, new methods have been added for picking files that return XFile instances (from the cross_file package) rather than the plugin's own PickedFile instances. While the previous methods still exist, it is already recommended to start migrating over to their new equivalents.
Handling MainActivity destruction on Android Android system -- although very rarely -- sometimes kills the MainActivity after the image_picker finishes. When this happens, we lost the data selected from the image_picker. You can use retrieveLostData to retrieve the lost data in this situation.
Starting with version 0.8.1 the iOS implementation uses PHPicker to pick (multiple) images on iOS 14 or higher. As a result of implementing PHPicker it becomes impossible to pick HEIC images on the iOS simulator in iOS 14+. This is a known issue.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With