ios - 不可重现的 webcore 崩溃

标签 ios objective-c ipad uiwebview crash

我有一个 iPad 应用程序在 App Store 上架了大约三个月,我一直收到一些我无法弄清楚的奇怪的崩溃报告。这些并没有那么频繁,自发布以来大约有 15-20 个实例,但仍然足够频繁以实际打扰我。崩溃略有不同(请参阅下面的堆栈跟踪),但由于它们与 WebCore 有关,我猜测它们与应用程序中 UIWebView 的使用有关,并且可能有一个共同的原因,尽管我不是 100% 肯定。该应用程序的部署目标是 iOS 6.0,但崩溃出现在 iPad 2、iPad 3 和 iPad Mini 上,仅限于 iOS 7。

我在应用程序中只有一个地方使用 WebView ,用于显示来自各种来源的新闻文章网页。我有一个 View Controller ,它有一个 UIWebView 作为它的 View 。这个 View Controller 的一个实例存在于整个应用程序中,每次选择一篇新文章时,现有的 webview 都会重新加载新选择文章的 url。

基于围绕 WebCore 问题的讨论提出的解决方案之一建议在 Controller 的 dealloc 方法中将 webviews delegate 属性设置为 nil。不幸的是,我认为它不适用于我的情况,因为 View Controller 在应用程序的生命周期内不会被释放。
另一个问题可能是不正确的网页在 CSS 中引用了错误的图像(loadPendingImages 崩溃)。不过我还找不到这样的页面。
此外,我仔细检查并确保在主线程上执行与 webview 相关的操作。

崩溃是

Exception Type: EXC_BAD_ACCESS 
Code: KERN_INVALID_ADDRESS

具有以下堆栈跟踪(完整的 here)

0 WebCore WebCore::StyleResolver::applyMatchedProperties(WebCore::StyleResolver::MatchResult const&, WebCore::Element const*) + 815
1 WebCore WebCore::StyleResolver::applyMatchedProperties(WebCore::StyleResolver::MatchResult const&, WebCore::Element const*) + 788
2 WebCore WebCore::StyleResolver::styleForElement(WebCore::Element*, WebCore::RenderStyle*, WebCore::StyleSharingBehavior, WebCore::RuleMatchingBehavior, WebCore::RenderRegion*) + 948
3 WebCore WebCore::Document::styleForElementIgnoringPendingStylesheets(WebCore::Element*) + 96
4 WebCore WebCore::Element::computedStyle(WebCore::PseudoId) + 142
5 WebCore WebCore::ComputedStyleExtractor::propertyValue(WebCore::CSSPropertyID, WebCore::EUpdateLayout) const + 458

0 WebCore WebCore::StyleResolver::loadPendingImages() + 1153
1 WebCore WebCore::ResourceRequestBase::~ResourceRequestBase() + 104
2 WebCore WebCore::StyleResolver::applyMatchedProperties(WebCore::StyleResolver::MatchResult const&, WebCore::Element const*) + 782
3 WebCore WebCore::StyleResolver::styleForElement(WebCore::Element*, WebCore::RenderStyle*, WebCore::StyleSharingBehavior, WebCore::RuleMatchingBehavior, WebCore::RenderRegion*) + 948
4 WebCore WebCore::Document::styleForElementIgnoringPendingStylesheets(WebCore::Element*) + 96
5 WebCore WebCore::Element::computedStyle(WebCore::PseudoId) + 142

0 WebCore WebCore::StyleResolver::adjustRenderStyle(WebCore::RenderStyle*, WebCore::RenderStyle*, WebCore::Element*) + 19
1 WebCore WebCore::StyleResolver::styleForElement(WebCore::Element*, WebCore::RenderStyle*, WebCore::StyleSharingBehavior, WebCore::RuleMatchingBehavior, WebCore::RenderRegion*) + 964
2 WebCore WebCore::Document::styleForElementIgnoringPendingStylesheets(WebCore::Element*) + 96
3 WebCore WebCore::Element::computedStyle(WebCore::PseudoId) + 142
4 WebCore WebCore::ComputedStyleExtractor::propertyValue(WebCore::CSSPropertyID, WebCore::EUpdateLayout) const + 458
5 WebCore WebCore::CSSComputedStyleDeclaration::getPropertyValue(WebCore::CSSPropertyID) const + 42

0 WebCore WebCore::TimerBase::heapDeleteMin() + 37
1 WebCore WebCore::ThreadTimers::sharedTimerFiredInternal() + 94
2 WebCore WebCore::ThreadTimers::sharedTimerFiredInternal() + 94
3 WebCore WebCore::timerFired(__CFRunLoopTimer*, void*) + 24
4 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
5 CoreFoundation __CFRunLoopDoTimer + 782

有没有人经历过类似的崩溃?如果是这样:
1. 有复制的方法吗?
2. 如何在不复制它们的情况下调试它们?
3. 哪些修复解决了问题?

谢谢!

最佳答案

我在我开发的一个应用程序中遇到了完全相同的问题,奇怪的是它只发生在运行 iOS 7 的旧设备上。我怀疑这与他们无法跟上进度有关。

我拥有的是一个 UITableView,其中一行会打开一个 UIViewController,其中有一个 UIWebView 用于自定义广告。我发现,在较旧的设备上,对象和内存的释放频率比我在其他平台上看到的要频繁得多。通过进入/离开屏幕 2 或 3 次,我可以很容易地在 iPhone 4 上模拟崩溃。作为 iPhone 5,我花了 15 分钟做同样的事情并且挑不出毛病。

我知道你可能觉得你的 Controller 没有被释放,但它听起来确实是,或者一些引用被删除了,我也看到我的委托(delegate)引用也在这个应用程序中消失了几次。

我的建议和对我有用的是停止 webview 的执行,并尽可能将所有内容设置为 nil

在我的应用程序的一个实例中,我选择在 viewWillDisappear 回调中执行此操作,因为在我的情况下它已从用户那里消失并稍后重新创建,所以我像这样消隐了所有内容:

[webView stopLoading];

self.webView.delegate = nil;
self.webView = nil;

关于ios - 不可重现的 webcore 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19859414/

相关文章:

ios - 复制 Google 的搜索 iOS 卡片动画

objective-c - 在两列中显示结果

iphone - 如何判断 UIView 何时获得焦点

html - Ipad 上带有文本的 css 过渡

ios - Quickblox iOS 下载聊天消息附件

ios - 使用 AFNetworking 进行 SSL 固定

ios - 搜索时状态栏消失

ios - 在 Swift 中实现 SRWebSocketDelegate

iphone - Xcode SDK 中缺少 Pragma Mark

ios - 无法在 google firebase 中存储 facebook 用户数据