UIWebDocumentView _updateSubviewCaches 在 iOS10 中崩溃 [英] UIWebDocumentView _updateSubviewCaches crash in iOS10

查看:25
本文介绍了UIWebDocumentView _updateSubviewCaches 在 iOS10 中崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 iOS10 中更严重地遇到了 HockeyApp 中的以下崩溃.请找到下面给出的崩溃日志.

I am getting the following crash in HockeyApp more seriously in iOS10. Please find the crash log as given below.

线程 4 崩溃:

0 libobjc.A.dylib 0x0000000187242f30 objc_msgSend + 16
1 UIKit 0x000000018e86e914 -[UIWebDocumentView _updateSubviewCaches] + 36
2 UIKit 0x000000018e69093c -[UIWebDocumentView subviews] + 88
3 UIKit 0x000000018e941bd4 -[UIView(CALayerDelegate) _wantsReapplicationOfAutoLayoutWithLayoutDirtyOnEntry:] + 68
4 UIKit 0x000000018e63d770 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1248
5 QuartzCore 0x000000018bb0640c -[CALayer layoutSublayers] + 144
6 QuartzCore 0x000000018bafb0e8 CA::Layer::layout_if_needed(CA::Transaction*) + 288
7 QuartzCore 0x000000018bafafa8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 28
8 QuartzCore 0x000000018ba77c64 CA::Context::commit_transaction(CA::Transaction*) + 248
9 QuartzCore 0x000000018ba9f0d0 CA::Transaction::commit() + 508
10 QuartzCore 0x000000018ba9faf0 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 116
11 CoreFoundation 0x00000001887a57dc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 28
12 CoreFoundation 0x00000001887a340c __CFRunLoopDoObservers + 368
13 CoreFoundation 0x00000001886d2068 CFRunLoopRunSpecific + 472
14 WebCore 0x000000018d273a2c RunWebThread(void*) + 452
15 libsystem_pthread.dylib 0x000000018788b860 _pthread_body + 236
16 libsystem_pthread.dylib 0x000000018788b770 _pthread_start + 280
17 libsystem_pthread.dylib 0x0000000187888dbc thread_start + 0

知道这里发生了什么吗?似乎以下崩溃组也相关.

Any idea what is going on here ? Seems like the following crash groups are also related.

崩溃组 1

[UIWebBrowserView _collectAdditionalSubviews]
objc_msgSend() selector name: autorelease

崩溃组 2

[UIWebDocumentView subviews]
objc_msgSend() selector name: arrayByAddingObjectsFromArray:

推荐答案

我正在回答我自己的问题,因为我能够复制这个问题并找到根本原因.

I am answering to my own question, since I am able to replicate this issue and found the root cause.

请注意以下事项.

1.我正在使用 UIWebView.首先,不建议这样做.

<强>2.以下实现方式会导致此问题.我这里写伪代码来演示这个问题.

@implementation MyViewController

    - (void)loadView {

        //creating UIWebView Here
        self.webView = [[UIWebView alloc] initWithFrame:_some_frame];

        //setting the web view properties here.

        //Adding to the view
        [self.view addSubView: self.webView];

        [self populateWebView];
    }

    - (void) populateWebView {
        [self.webView loadHTMLString:_some_html 
                             baseURL:[NSURL fileURLWithPath:_some_path]];
    }


    - (void)viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];

        if (self.webView) {
           //The following two lines causing this issue.
           self.webView.scrollView.contentInset = _some_insets;
           self.webView.scrollView.scrollIndicatorInsets = _some_insets;
        }
    }

@end

3.解决方法如下.

@implementation MyViewController

    - (void)loadView {

        //creating UIWebView Here
        self.webView = [[UIWebView alloc] initWithFrame:_some_frame];

        //setting the web view properties here.

        //Adding to the view
        [self.view addSubView: self.webView];

        [self populateWebView];
    }

    - (void) populateWebView {
        [self.webView loadHTMLString:_some_html 
                             baseURL:[NSURL fileURLWithPath:_some_path]];
    }


    - (void)viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
    }

    - (void)webViewDidFinishLoad:(UIWebView *)webView {
        webView.scrollView.contentInset = _some_insets;
        webView.scrollView.scrollIndicatorInsets = _some_insets;
    }

@end

在我的实际代码中,我在这里通过继承 UIWebView 来使用自定义 WebView 类.不认为这会产生一些问题.根本原因是在 viewDidLayoutSubviews 中设置contentInset"和scrollIndicatorInsets",这不是一个好主意.当我放置断点时,viewDidLayoutSubviews"调用了几次,最终应用程序崩溃.

In my actual code, I was using a custom WebView class here by subclassing the UIWebView. Not think that will create some issue. The root cause is setting the "contentInset" and "scrollIndicatorInsets" in viewDidLayoutSubviews which is not a good idea. When I put the break points, "viewDidLayoutSubviews" called several times and eventually App crashes.

作为一种解决方案,我将以下部分代码移到webViewDidFinishLoad"中,只有在完成加载后 WebView 准备就绪时才会调用.所以在这个委托方法下添加这段代码是有意义的.

As a solution I moved the following part of the code into "webViewDidFinishLoad" which will call only when the WebView is ready after finished loading. So it makes sense to add this code under this delegate method.

webView.scrollView.contentInset = _some_insets;
webView.scrollView.scrollIndicatorInsets = _some_insets;

这篇关于UIWebDocumentView _updateSubviewCaches 在 iOS10 中崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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