Modal View Closes When Selecting an Image in Uiwebview iOS

Modal view closes when selecting an image in UIWebView iOS

I encountered the same issue. I found that the file upload action sheet tries to dismiss itself twice upon selecting an option, which results in the modal being dismissed as well.

A solution is to subclass the UINavigationController containing the webview and override dismissViewControllerAnimated to ignore it unless it actually has a presentedViewController.

Like so:

override func dismissViewControllerAnimated(flag: Bool, completion: (() -> Void)?) {
if (self.presentedViewController != nil) {
super.dismissViewControllerAnimated(flag, completion: completion)
}
}

If you're not using a navigation controller, just override this method in the webview instead.

WebView dismissed if choose file and select photo Library


  1. Set Delegate to webview.

    webView.delegate = self

  2. Then after call delegate method of webview.

    func webViewDidFinishLoad(_ webView: UIWebView)

    Enter your code above method of choose file and select photo Library.

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

uploading image in uiwebview from uiimagepicker

Try this

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info    
{
NSURL *urlPath = [info valueForKey:UIImagePickerControllerReferenceURL];
UIImage *cameraImage = [info valueForKey:UIImagePickerControllerOriginalImage];
NSData *myData = UIImagePNGRepresentation(cameraImage);
[self.webview loadData:myData MIMEType:@"image/png" textEncodingName:nil baseURL:nil];
[self.picker dismissViewControllerAnimated:YES completion:nil];
}

Upload photo with UIWebView

It's a bug on iOS 8, that happens when the webview is presented modally.

The only options right now it not to present the webview modally, you can present it with a navigation controller or switching the rootviewcontroller

Here you can read more about the bug and a proposed solution

iOS 8 SDK: modal UIWebView and camera/image picker

iOS 8.0 UIWebView file input crashes my App

The solution to this problem is as Joel Jeske writes, you have to rebuild your App against iOS 8. This is the only solution to this problem.
Rebuilding against iOS 8 will also make the App run on iOS 7/6 without any problem.

Detecting when native select widget is opened/closed in UIWebView

I'm surprised that the scroll event isn't firing. MDN has a list of events that can be bound to that might be of help to you.

A quick thought that jumps out to me is that you could bind to the mouseup and input/change events on the select and in their callbacks determine what the scrollTop is as the user interacts with the select. If you have multiple selects you need to track, you could delegate the events to the body to avoid creating additional listeners.

Polling would work, but it'd be a lot less efficient then adding a few event listeners on the select itself, so hopefully you can find an event that works.

Hope that helps!



Related Topics



Leave a reply



Submit