美文网首页
iOS UIWebView打开相册的问题

iOS UIWebView打开相册的问题

作者: 村里竹竿 | 来源:发表于2017-09-07 10:30 被阅读248次

    这个问题在很早的时候遇到过一次,当时的解决办法通过push 而不是 modal 的方法。 但是这次又遇到了,而且不能用push的方法来解决了。so 能怎么办???

    上链接:iOS 8 SDK: modal UIWebView and camera/image picker

    对于这个问题出现的原因。里面有一段描述,原文是这样的。
    The uiwebview causes the uialertcontroller to be presented on the uiwebviewviewcontroller to show the camera/existing/cancel. When user chooses option, then uialertcontroller is meant to be dismissed and the uuiimagepickercontroller presented. However the dismissing of the uialertcontroller seems to fire twice. The first time is ok because the presentedviewcontroller = the uialertcontroller , but the 2nd time the presentedviewcontroller property is nil, and this causes the dismissviewcontrolleranimated method to kill the webviewviewcontroller which is the problem, to I now test for this case。

    大概意思就是:点击了 UIWebView 中打开相机的标签的时候,弹出了 UIAlertController, UIAlertController是通过modal到 UIWebView,当你点击了选项卡里面的选项的时候, UIAlertController 的dismissing执行了两次,第一次dismiss的是UIAlertController,但是第二次dismiss的是UIWebViewVC。

    这样一来就知道了问题的原因,原来是点击UIWebView中弹出选择相机的选项卡的时候,当我选中了从相机打开后,这个对话框dismiss了两次,所以就导致了UIWebView所在的控制器也消失了。如果这个UIWebView所在的控制器是跟控制器的话,就会引起崩溃。

    下面是解决办法。
    你可以在你自定义的UINavigationController中添加以下代码,或者在UINavigationController的分类中添加一下代码。重写dismiss的代码

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

    相关文章

      网友评论

          本文标题:iOS UIWebView打开相册的问题

          本文链接:https://www.haomeiwen.com/subject/bwobjxtx.html