I have a situation where I am trying to resolve these Crashlytics issues and I have this crash log
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)
I can understand that its some callback on webview delegate and bad excess has occurred, so to rectify this I handled the delegates via
[self.webview stopLoading];
self.webview.delegate =nil;
in all the classes, yet I can see this crash. Can you enlighten me what's possibly going wrong and some approach to rectify this?
Are you adding a web view within your subclass of a web view? Generally that's the problem and if so, changing the superclass to a UIView would solve the problem.
The following might be the case here
UIWebView
UIViewController
setsself
as the delegate Web page starts downloadingUIViewController
gets deallocatedUIWebView
finishes loading and sends I am finished loading message to its delegateor
some other delegate method gets called when the webview object is no more.i.e dangling pointer effect
1.Always make sure you stop loading the webView and remove the delegate before leaving the view
Here is the reference
2.Make sure you are not
stopLoading
andsetDelegate
to nil inviewWillDisappear
3.Make sure you set the
ContentOffset
of thesubviews
ofwebview
toCGPointZero
without animationso its better to you call the following code of in parent viewcontroller before closing it
Hope this helps.Feel free to ask your doubts.
4.Generally speaking You should not embed
UIWebView
objects inUIScrollView
objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.Here is the reference
Try disabling your UIWebView's scrolling behaviour before the ViewController deallocs it
p.s. Dipen Chudasama's approach is correct, according to Apple's documentation, you should really set the delegate property to nil before releasing the webview, assuming you have released the webview correctly inside
dealloc
function but notviewWillDisappear
Use visa versa means first nil your delegate and then after stop loading web view may be help you.
like this.
As per apple document : Important Before releasing an instance of UIWebView for which you have set a delegate, you must first set its delegate property to nil.
UIWebView
sdelegate
usesassign
and notweak
. So you need to nullify thedelegate
when thewebView
's controller gets deallocated.Example:
Use [listener use] instead, to tell your
UIWebView
to handle clicked URL.