iOS 8 SDK:模态 UIWebView 和相机/图像选择器 [英] iOS 8 SDK: modal UIWebView and camera/image picker

查看:16
本文介绍了iOS 8 SDK:模态 UIWebView 和相机/图像选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,在为 iOS 8 编译(并在 iOS 8 中运行)时,如果 UIWebView 位于视图控制器以模态方式呈现.它在直接挂"在窗口 rootViewController 上的视图控制器或从它推送的视图控制器中工作没有问题.

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.

可以在 https://dl.dropboxusercontent.com/u/6214425/TestModalWebCamera 找到测试应用程序.zip 但我会在下面描述它.

The test application can be found at https://dl.dropboxusercontent.com/u/6214425/TestModalWebCamera.zip but I will describe it below.

我的测试应用程序(使用故事板构建,但真正的应用程序不使用它们)有两个视图控制器(原名为 ViewControllerViewController2).ViewController 包含在作为根视图控制器的 UINavigationController 中.ViewController 包含一个 UIWebView(工作正常)、一个显示"(推送")按钮 ViewController2 和一个 UIBarButtonItem 以模态方式呈现 ViewController2.ViewController2 有另一个 UIWebView,它在推送"时有效,但在呈现"时无效.

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".

ViewControllerViewController2 都加载了:

- (void)viewDidLoad {
  [super viewDidLoad];

  [self.webView loadHTMLString:@"<input type="file" accept="image/*;capture=camera">" baseURL:nil];
}

当尝试使用模态 UIWebView Xcode 在控制台中打印以下内容并关闭应用模态:

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!

我目前的理论是 UIActionSheetUIAlertController 的变化可能会产生这种情况,但很难证明.以防万一,我会和 Apple 开一个 Radar.

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?

推荐答案

我发现在 iOS 8.0.2 iPad 似乎没有这个 bug 但 iPhone 仍然存在.

I found that in iOS 8.0.2 iPad does not seem to have that bug but iPhone still does.

但是,在包含 uiwebview 的视图控制器中覆盖以下内容

However, overriding following in the view controller containing the uiwebview

-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion

并且检查是否存在presentedViewController 似乎有效.

And checking that there is a presentedViewController seems to work.

但需要检查副作用

#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

这篇关于iOS 8 SDK:模态 UIWebView 和相机/图像选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆