Crash in UIKit related to WebView - ios

I have a random crash in UIKit that happend a couple of times already.
It crashes with EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x0000000d
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x30e08f46 objc_msgSend + 5
1 UIKit 0x26d1790d -[_UIWebViewScrollViewDelegateForwarder forwardInvocation:] + 140
2 CoreFoundation 0x23654def ___forwarding___ + 354
3 CoreFoundation 0x23586df8 _CF_forwarding_prep_0 + 24
4 UIKit 0x26b5a6fd -[UIScrollView _getDelegateZoomView] + 84
5 UIKit 0x26b5a635 -[UIScrollView _zoomScaleFromPresentationLayer:] + 24
6 UIKit 0x26b5a5ed -[UIWebDocumentView _zoomedDocumentScale] + 64
7 UIKit 0x26b5a13d -[UIWebDocumentView _layoutRectForFixedPositionObjects] + 104
8 UIKit 0x26b59f97 -[UIWebDocumentView _updateFixedPositionedObjectsLayoutRectUsingWebThread:synchronize:] + 38
9 UIKit 0x26b5c3e5 -[UIWebDocumentView _updateFixedPositioningObjectsLayoutAfterScroll] + 28
10 UIKit 0x26b5c3c1 -[UIWebBrowserView _updateFixedPositioningObjectsLayoutAfterScroll] + 56
11 CoreFoundation 0x2360a281 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
12 CoreFoundation 0x2356652d _CFXNotificationPost + 1784
13 Foundation 0x24296189 -[NSNotificationCenter postNotificationName:object:userInfo:] + 72
14 UIKit 0x27171dd7 -[UIInputWindowController postEndNotifications:withInfo:] + 554
15 UIKit 0x271732ed __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke595 + 368
16 UIKit 0x26b44b05 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 308
17 UIKit 0x26b4471d -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 184
18 UIKit 0x26b4462f -[UIViewAnimationState animationDidStop:finished:] + 66
19 QuartzCore 0x2653d2d9 CA::Layer::run_animation_callbacks(void*) + 236
20 libdispatch.dylib 0x3135c7a7 _dispatch_client_callout + 22
21 libdispatch.dylib 0x3135ffa3 _dispatch_main_queue_callback_4CF + 718
22 CoreFoundation 0x236179d1 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
23 CoreFoundation 0x236160d1 __CFRunLoopRun + 1512
24 CoreFoundation 0x23564211 CFRunLoopRunSpecific + 476
25 CoreFoundation 0x23564023 CFRunLoopRunInMode + 106
26 GraphicsServices 0x2a95d0a9 GSEventRunModal + 136
27 UIKit 0x26b701d1 UIApplicationMain + 1440
28 MY_PROJECT 0x000842cf main (main.m:16)
It looks like it is related to UIWebView, but I have no clue what happened - any help is appreciated
The crash seems to be known in China ...

As mentioned by # NilsHolgerson I had a some issues with notifications.
The most probable reason was a notification that was not properly removed and that did retain a ViewController that was detached otherwise:
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillEnterForegroundNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
...
The solution looks as follows:
__weak typeof(self) weakself = self;
__block NSObject *reference = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillEnterForegroundNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
[[NSNotificationCenter defaultCenter] removeObserver:reference];
...

The deeply reason of this issues is: Container ViewController has been released when webView doing some animations.
So the directly solution is set webView's delegate to nil when ViewControllers dealloc.
Of course if you release VC appropriately as #dogsgod do is also a solution.

Related

KVO observer crash on iOS 11

I’ve a app in App Store which was working fine on iOS 10. But recently I’m getting many crash reports and all logs points to KVO crash and all are happening on iOS 11, below is the crash log.
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x181e7a858 object_isClass + 16
1 Foundation 0x1836d72bc KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED + 68
2 Foundation 0x1836d5ad0 NSKeyValueWillChangeWithPerThreadPendingNotifications + 300
3 QuartzCore 0x186e35024 -[CALayer setDelegate:] + 108
4 UIKit 0x18c866698 -[UIView dealloc] + 708
5 UIKit 0x18c93f08c -[UILabel dealloc] + 192
6 libobjc.A.dylib 0x181e9a13c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 844
7 UIKit 0x18c86678c -[UIView dealloc] + 952
8 CoreFoundation 0x182b911b4 -[__NSArrayM dealloc] + 140
9 libobjc.A.dylib 0x181e9a13c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 844
10 UIKit 0x18c86678c -[UIView dealloc] + 952
11 libobjc.A.dylib 0x181e9a13c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 844
12 UIKit 0x18c86678c -[UIView dealloc] + 952
13 libobjc.A.dylib 0x181e9a13c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 844
14 UIKit 0x18c86678c -[UIView dealloc] + 952
15 UIKit 0x18cbd3248 -[UINavigationTransitionView dealloc] + 96
16 libobjc.A.dylib 0x181e9a13c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 844
17 UIKit 0x18c86678c -[UIView dealloc] + 952
18 UIKit 0x18cbd319c -[UILayoutContainerView dealloc] + 60
19 libobjc.A.dylib 0x181e9a13c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 844
20 CoreFoundation 0x182b88aac _CFAutoreleasePoolPop + 28
21 UIKit 0x18cc705fc _prepareForCAFlush + 132
22 UIKit 0x18cb555b8 _afterCACommitHandler + 236
23 CoreFoundation 0x182c6a910 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
24 CoreFoundation 0x182c68238 __CFRunLoopDoObservers + 412
25 CoreFoundation 0x182c68884 __CFRunLoopRun + 1436
26 CoreFoundation 0x182b88da8 CFRunLoopRunSpecific + 552
27 GraphicsServices 0x184b6b020 GSEventRunModal + 100
28 UIKit 0x18cb6978c UIApplicationMain + 236
29 MyApp 0x1009bf748 main (main.m:14)
30 libdyld.dylib 0x182619fc0 start + 4
The crashes has crossed over 200 crashes and all are same logs. I’ve not been able to reproduce this crash and kind of stuck on how to proceed next. My entire project is written in objective-C and when I checked there is only one method where I’m using a KVO. Below is a model of my method on how I’ve used it.
-(void)loadData
{
//Some code
if (myAlerts) {
[myAlerts removeObserver:self forKeyPath:#“liveAlerts"];
}
myAlerts = myModel.alerts;
[myAlerts addObserver:self forKeyPath:#"liveAlerts" options:NSKeyValueObservingOptionInitial context:NULL];
}
To remove I use the cleanup method in other viewcontrollers when I no longer need it
-(void)cleanup
{
//Some code
[myAlerts removeObserver:self forKeyPath:#"liveAlerts"];
myAlerts = nil;
}
All the other observers which I've added in my project are NSNotificationCenter observers, could that cause this type of crash log?

EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000002 on UITableView reloadData

I've had this problem for a while and it's driving me nuts. This is reported by Crashlytics but only for a few users. I'm unable to recreate the problem myself.
I'm using a SplitViewController and this occurs after a user adds data within a UIViewController and touch the save button, which then returns to the SplitViewController to perform the method 'saveItemEntry' shown below.
I've tried a suggestion from a previous post which was to wrap the [self.tableView reloadData] with dispatch_async(dispatch_get_main_queue(), ^(void), but that actually made it worse. It isn't like the data takes ages to load, it doesn't, so I can't see that multi-tasking will help, but I'm open to advice on whether I should be doing that.
I'm really not clear on how to interperupt the crash info. If someone can and can suggest what might be causing this that would be awesome.
If more info is needed please let me know.
Here's the crash details:
Here's the Raw stuff..
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x20407ae2 objc_msgSend + 1
1 CoreFoundation 0x20b8391b -[NSDictionary descriptionWithLocale:indent:] + 310
2 Foundation 0x2136fe2d _NSDescriptionWithLocaleFunc + 60
3 CoreFoundation 0x20c011a3 __CFStringAppendFormatCore + 7986
4 CoreFoundation 0x20bff255 _CFStringCreateWithFormatAndArgumentsAux2 + 80
5 CoreFoundation 0x20c17559 _CFLogvEx2 + 96
6 CoreFoundation 0x20c179af _CFLogvEx3 + 118
7 Foundation 0x214374f7 _NSLogv + 126
8 Foundation 0x2137e79d NSLog + 28
9 UIKit 0x24eac5fb -[UITableView reloadData] + 1818
10 Simple Meeting Minutes 0xfb859 -[MMDetailTableVC saveItemEntry:] (MMDetailTableVC.m:1423)
11 Simple Meeting Minutes 0x10becf -[MMItemViewController saveButtonAction:] (MMItemViewController.m:526)
12 UIKit 0x24dfd771 -[UIApplication sendAction:to:from:forEvent:] + 80
13 UIKit 0x24f7ec71 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 140
14 UIKit 0x24dfd771 -[UIApplication sendAction:to:from:forEvent:] + 80
15 UIKit 0x24dfd701 -[UIControl sendAction:to:forEvent:] + 64
16 UIKit 0x24de561f -[UIControl _sendActionsForEvents:withEvent:] + 446
17 UIKit 0x24de574b -[UIControl _sendActionsForEvents:withEvent:] + 746
18 UIKit 0x24dfd051 -[UIControl touchesEnded:withEvent:] + 616
19 UIKit 0x24dfccbf -[UIWindow _sendTouchesForEvent:] + 646
20 UIKit 0x24df55d7 -[UIWindow sendEvent:] + 642
21 UIKit 0x24dc6119 -[UIApplication sendEvent:] + 204
22 UIKit 0x24dc4757 _UIApplicationHandleEventQueue + 5134
23 CoreFoundation 0x20bf1257 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
24 CoreFoundation 0x20bf0e47 __CFRunLoopDoSources0 + 454
25 CoreFoundation 0x20bef1af __CFRunLoopRun + 806
26 CoreFoundation 0x20b41bb9 CFRunLoopRunSpecific + 516
27 CoreFoundation 0x20b419ad CFRunLoopRunInMode + 108
28 GraphicsServices 0x21dbbaf9 GSEventRunModal + 160
29 UIKit 0x24e2dfb5 UIApplicationMain + 144
30 Simple Meeting Minutes 0xf5d6f main (main.m:16)
31 libdispatch.dylib 0x207f4873 (Missing)
and here's my code in this particular area..
- (void)saveItemEntry:(MMitem *)item{
if (item)
{
// save item to the sqlite3 database file
NSString *resultStr = [self.meetingModel saveItem:item];
if ([resultStr isEqualToString:#"OK"])
{
// all good so close form and refresh data
[self dismissViewControllerAnimated:NO completion:nil];
[self.tableView reloadData];
// or if there is an error result then display message
}
else if ([resultStr isEqualToString:#"DescriptionNotesMissing"])
{
[self showAlert:#"Missing Description or Notes" :#"An Item Description or Notes is required" :0];
[self.itemViewController.itemDescription becomeFirstResponder];
}
// for any other error do nothing
}
}

iOS app crashed when enter text in UiWebView

In my iOS(Objective C) app, I am loading a UIWebView in a UIView and it just lead to the App crash when I click on a Text field in the webview, say in Google if I just touch the text field to enter some keyword the app will crash. I am able to open the webView in sample app, but it fails in my project.
I have user the strong reference for the variables. Error is:
-[__NSCFSet keyboardWillShow:]: unrecognized selector sent to instance 0x8fa0140
2014-08-25 12:15:40.626 Travelara[1263:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFSet keyboardWillShow:]: unrecognized selector sent to instance 0x8fa0140'
*** First throw call stack:
(
0 CoreFoundation 0x01c7a1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x019778e5 objc_exception_throw + 44
2 CoreFoundation 0x01d17243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01c6a50b ___forwarding___ + 1019
4 CoreFoundation 0x01c6a0ee _CF_forwarding_prep_0 + 14
5 Foundation 0x0164a049 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
6 CoreFoundation 0x01cd5f04 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
7 CoreFoundation 0x01c2defb _CFXNotificationPost + 2859
8 Foundation 0x01583e41 -[NSNotificationCenter postNotificationName:object:userInfo:] + 98
9 UIKit 0x00af1625 -[UIInputViewTransition postNotificationsForTransitionStart] + 1004
10 UIKit 0x00ae7562 -[UIPeripheralHost(UIKitInternal) executeTransition:] + 592
11 UIKit 0x00ae9a79 -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 929
12 UIKit 0x00ae9e7e -[UIPeripheralHost(UIKitInternal) setInputViews:animated:] + 72
13 UIKit 0x00ae9ec8 -[UIPeripheralHost(UIKitInternal) setInputViews:] + 67
14 UIKit 0x00ae0fb1 -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 1448
15 UIKit 0x0079d8b4 -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 287
16 UIKit 0x00b0a6b5 -[UIWebBrowserView assistFormNode:] + 265
17 UIKit 0x0087e435 __47-[UIWebDocumentView(Interaction) performClick:]_block_invoke172 + 52
18 libdispatch.dylib 0x02e784d0 _dispatch_client_callout + 14
19 libdispatch.dylib 0x02e67439 _dispatch_barrier_sync_f_slow_invoke + 80
20 libdispatch.dylib 0x02e784d0 _dispatch_client_callout + 14
21 libdispatch.dylib 0x02e66726 _dispatch_main_queue_callback_4CF + 340
22 CoreFoundation 0x01cdf43e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
23 CoreFoundation 0x01c205cb __CFRunLoopRun + 1963
24 CoreFoundation 0x01c1f9d3 CFRunLoopRunSpecific + 467
25 CoreFoundation 0x01c1f7eb CFRunLoopRunInMode + 123
26 GraphicsServices 0x034145ee GSEventRunModal + 192
27 GraphicsServices 0x0341442b GSEventRun + 104
28 UIKit 0x00637f9b UIApplicationMain + 1225
29 Travelara 0x0007b34d main + 141
30 libdyld.dylib 0x030ad701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The code I am using is:
self.webview1=[[UIWebView alloc]initWithFrame:CGRectMake (10,70,292,430)];
self.webview1.backgroundColor= [UIColor whiteColor];
self.webview1.userInteractionEnabled=true;
self.webview1.multipleTouchEnabled=true;
self.webview1.delegate=self;
[self addSubview:self.webview1];
self.url=#"https://www.google.co.in/";
self.nsurl=[NSURL URLWithString:self.url];
self.nsrequest=[NSURLRequest requestWithURL:self.nsurl];
[self.webview1 loadRequest:self.nsrequest];
Please help me to solve the issue.
although the source code is not enough to make accurate guess but looks like you defined something like
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
to get event event notification about keyboard display but forgot to define the functions
- (void)keyboardWillShow:(NSNotification *)aNotification {
[self performSelector:#selector(readjustWebviewScroller) withObject:nil afterDelay:0];
}
Please check.

How to diagnose crash report

I have a UIViewController:DFUserChatViewController witch is inherit form DFChatViewController,in DFChatViewController init method I have a navigationItem.leftBarButtonItem with a method backAction
- (id)init
{
self = [super init];
if (self)
{
...........
self.navigationItem.leftBarButtonItem = [[[DFBarBackButtonItem alloc] initWithTarget:self action:#selector(backAction:) image:nil] autorelease];
}
return self;
}
in DFUserChatViewController I overwrite the method backAction:
#pragma mark - action
-(void)backAction:(id)sender
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
.............any other thing
.............
{
[self.navigationController popViewControllerAnimated:YES];
}
}
I use crashlytics for crash report and today I receive a crash
0
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x4000000c
raw
0
libobjc.A.dylib objc_msgSend + 5
1
DFmyPro
DFUserChatViewController.m line 349
-[DFUserChatViewController backAction:]
2
UIKit -[UIApplication sendAction:to:from:forEvent:] + 90
3
UIKit -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 30
4
UIKit -[UIControl sendAction:to:forEvent:] + 44
5
UIKit -[UIControl _sendActionsForEvents:withEvent:] + 374
6
UIKit -[UIControl touchesEnded:withEvent:] + 590
7
UIKit -[UIWindow _sendTouchesForEvent:] + 528
8
UIKit -[UIWindow sendEvent:] + 832
9
DFmyPro
DFShakeWindow.m line 46
-[DFShakeWindow sendEvent:]
10
UIKit -[UIApplication sendEvent:] + 196
11
UIKit _UIApplicationHandleEventQueue + 7098
12 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
13
CoreFoundation __CFRunLoopDoSources0 + 206
14
CoreFoundation __CFRunLoopRun + 622
15
CoreFoundation CFRunLoopRunSpecific + 522
16
CoreFoundation CFRunLoopRunInMode + 106
17
GraphicsServices GSEventRunModal + 138
18 UIKit UIApplicationMain + 1136
19
DFmyPro
main.m line 15
main
I run my app again and again ,and didn‘t catch the crash ,How do I know where goes wrong

Why removeObserver causes objc_msgSend SIGSEGV in viewWillDisappear in this code?

First of all, it is a crash that I can not reproduce so I can not debug in Xcode. So I'm trying to reason it.
Stack trace:
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0xc
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x3a816b26 objc_msgSend + 5
1 Voodo 2 0x000d8933 -[TagListViewController viewWillDisappear:] (TagListViewController.m:107)
2 UIKit 0x32b68169 -[UIViewController _setViewAppearState:isAnimating:] + 472
3 UIKit 0x32bc602b -[UIViewController viewWillMoveToWindow:] + 290
4 UIKit 0x32b4be89 -[UIView _willMoveToWindow:] + 468
5 UIKit 0x32b6e4df -[UIScrollView _willMoveToWindow:] + 122
6 UIKit 0x32b4c7b5 __85-[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:]_block_invoke + 77
7 UIKit 0x32b4c6e5 -[UIView _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 376
8 UIKit 0x32b4c7d5 __85-[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:]_block_invoke + 109
9 UIKit 0x32b4c6e5 -[UIView _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 376
10 UIKit 0x32b4c7d5 __85-[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:]_block_invoke + 109
11 UIKit 0x32b4c6e5 -[UIView _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 376
12 UIKit 0x32b4c7d5 __85-[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:]_block_invoke + 109
13 UIKit 0x32b4c6e5 -[UIView _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 376
14 UIKit 0x32de333b __UIViewWillBeRemovedFromSuperview + 379
15 UIKit 0x32b4badd -[UIView removeFromSuperview] + 56
16 UIKit 0x32b4e407 -[UIView dealloc] + 366
17 UIKit 0x32d3c0f1 -[UIWindow dealloc] + 824
18 libobjc.A.dylib 0x3a818007 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 359
19 CoreFoundation 0x3030e981 _CFAutoreleasePoolPop + 16
20 UIKit 0x32b4624d _wrapRunLoopWithAutoreleasePoolHandler + 37
21 CoreFoundation 0x303a61cd __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 21
22 CoreFoundation 0x303a3b71 __CFRunLoopDoObservers + 285
23 CoreFoundation 0x303a3eb3 __CFRunLoopRun + 731
24 CoreFoundation 0x3030ec27 CFRunLoopRunSpecific + 522
25 CoreFoundation 0x3030ea0b CFRunLoopRunInMode + 106
26 GraphicsServices 0x35035283 GSEventRunModal + 138
27 UIKit 0x32bb2049 UIApplicationMain + 1136
28 Voodo 2 0x000c87df main (main.m:14)
29 libdyld.dylib 0x3ad23ab7 start + 3
The code is very simple and using ARC:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self refresh];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(refresh) name:NSManagedObjectContextDidSaveNotification object:self.managedObjectContext];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(refresh) object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSManagedObjectContextDidSaveNotification object:self.managedObjectContext];
}
- (void)refresh {
[self.tableView reloadData];
// Refresh every 60s.
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(refresh) object:nil];
[self performSelector:#selector(refresh) withObject:nil afterDelay:60];
}
The crash occurs at the last line.
The only possible cause I can think of is that the cancelPreviousPerformRequestsWithTarget:selector:object: call releases the last reference to self so self is dangling at the last line. However, I can not find any possible path for this situation to happen.

Resources