我有一种情况,我正在尝试解决这些 Crashlytics 问题并且我有这个崩溃日志
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x34217f46 objc_msgSend + 5
1 UIKit 0x29a2d5a3 -[UIWebView webView:decidePolicyForNavigationAction:request:frame:decisionListener:] + 182
2 CoreFoundation 0x2630cad4 __invoking___ + 68
3 CoreFoundation 0x26239645 -[NSInvocation invoke] + 300
4 CoreFoundation 0x2623d0c7 -[NSInvocation invokeWithTarget:] + 50
5 WebKitLegacy 0x326d9261 -[_WebSafeForwarder forwardInvocation:] + 224
6 CoreFoundation 0x2630b62f ___forwarding___ + 354
7 CoreFoundation 0x2623d008 _CF_forwarding_prep_0 + 24
8 CoreFoundation 0x2630cad4 __invoking___ + 68
9 CoreFoundation 0x26239645 -[NSInvocation invoke] + 300
10 WebCore 0x31c02729 HandleDelegateSource(void*) + 100
11 CoreFoundation 0x262cefbf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
12 CoreFoundation 0x262ce461 __CFRunLoopDoSources0 + 364
13 CoreFoundation 0x262cca35 __CFRunLoopRun + 772
14 CoreFoundation 0x2621a3b1 CFRunLoopRunSpecific + 476
15 CoreFoundation 0x2621a1c3 CFRunLoopRunInMode + 106
16 GraphicsServices 0x2d801201 GSEventRunModal + 136
17 UIKit 0x2988443d UIApplicationMain + 1440
18 abc 0x0030dcd7 main (main.m:14)
我可以理解它在 webview 委托(delegate)上的一些回调并且发生了严重的过度,所以为了纠正这个我通过处理委托(delegate)
[self.webview stopLoading];
self.webview.delegate =nil;
在所有类(class)中,但我可以看到此崩溃。您能否告诉我可能出了什么问题以及纠正此问题的一些方法?
最佳答案
下面可能是这种情况
- 向用户呈现一个带有
UIWebView
的屏幕 UIViewController
将self
设置为 delegate 网页开始下载- 用户退出屏幕
UIViewController
deallocatedUIWebView
完成加载并发送 I am finished loading 消息给它的 delegate
或
当 webview 对象不存在时,会调用其他一些委托(delegate)方法。即悬挂指针效果
1.始终确保在离开 View 之前停止加载 webView 并移除委托(delegate)
Before releasing an instance of UIWebView for which you have set a delegate, you must first set its delegate property to nil. This can be done, in your
dealloc
method
这是 reference
// If ARC is used
- (void)dealloc {
[_webView setDelegate:nil];
[_webView stopLoading];
}
// If ARC is not used
- (void)dealloc {
[webView setDelegate:nil];
[webView stopLoading];
[webView release];
[super dealloc];
}
// ARC - Before iOS6 as its deprecated from it.
- (void)viewWillUnload {
[webView setDelegate:nil];
[webView stopLoading];
}
2.确保你没有在 viewWillDisappear
中 stopLoading
和 setDelegate
到 nil
if the ViewController is a child of a another ViewController, u can trigger the removal of the ViewController's view from the parent ViewController's view with an animation. At the same time, u can remove the ViewController from its parent and
nil
out its reference. at this pointViewController
will benil
andviewWillDisappear
will never be called, meaning the WebView delegate will never be cleaned upUse
dealloc
and ensure that your WebView is always cleaned up.
3.确保将 webview
的 subviews
的 ContentOffset
设置为 CGPointZero
without animation
In iPad in some versions while webview is scrolling if you close the parent viewcontroller without setting ContentOffset to
CGPointZero
this kind of problems will come
所以最好在关闭之前在父 View Controller 中调用以下代码
for (id subview in webView.subviews){
if ([[subview class] isSubclassOfClass: [UIScrollView class]]){
[subview setContentOffset:CGPointZero animated:NO];
}
}
希望这对您有所帮助。如有疑问,请随时提出。
4.一般来说,您不应该在UIScrollView
对象中嵌入 UIWebView
对象。如果这样做,可能会导致意外行为,因为两个对象的触摸事件可能会混淆并错误处理。
这是 reference
关于ios:EXC_BAD_ACCESS 用于 Webview 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29139034/