iOS 8 Sdk: Modal Uiwebview and Camera/Image Picker

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];
}

UIWebView opening the camera and images when a button is clicked

I have managed to fix the issue and it goes way back to bug that was found in iOS 8 that still hasn't been fixed. Its to do with how the UIWebView is being presented.

Adding this code fixed it.

 -(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
if ( self.presentedViewController)
{
[super dismissViewControllerAnimated:flag completion:completion];
}
}

For any one else confused or struggling with this Note that you do not need to start messing around with UIImagePicker or UIWebView delegates. Your web view should take care of opening the camera library or camera. This was a real pain of an issue so hopefully this may help others in my position. you can also see THIS Question as this is where i got my answer from. Thanks Andrey for helping too

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



Related Topics



Leave a reply



Submit