-[XBMessage messageHash]: unrecognized selector sent to instance - ios

I've integrated following library from Cocoapods, You may find the code and its sample code at https://github.com/EugeneNguyen/XBChatModule
pod 'XBChatModule'
This library is used to integrate XMPP Chat in Xcode project.
I also added suggested code from its ReadMe file. For your reference I am pasting it below
AppDelegate.m
[[XBChatModule sharedInstance] setUsername:#"admin"];
[[XBChatModule sharedInstance] setPassword:#"admin"];
[[XBChatModule sharedInstance] setHost:#"sflashcard.com"];
[[XBChatModule sharedInstance] connect];
[[XBChatModule sharedInstance] setAvatarFormat:#"http://dev.sflashcard.com/images/mantis_logo.png?test=%#"];
[[XBChatModule sharedInstance] setAvatarPlaceHolder:[UIImage imageNamed:#"girl_9"]];
The View controller is inherited from XBMessageViewController
ViewController.m
- (void)viewDidLoad
{
self.jidStr = #"binh.nx#sflashcard.com";
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated
{
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(reloadData) name:#"XBChatModuleNewAvatar" object:nil];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)reloadData
{
[self.collectionView performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
The code works fine until I send a message. Whenever I press send button, it crashes the app by throwing following error in console
2015-09-01 17:20:41.742 Test[16064:251944] -[XBMessage messageHash]: unrecognized selector sent to instance 0x7ffc91cc4180
2015-09-01 17:20:41.800 Test[16064:251944] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[XBMessage messageHash]: unrecognized selector sent to instance 0x7ffc91cc4180'
*** First throw call stack:
(
0 CoreFoundation 0x000000011260aa75 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001122a3bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000112611d1d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001125697ef ___forwarding___ + 495
4 CoreFoundation 0x0000000112569578 _CF_forwarding_prep_0 + 120
5 Test 0x000000010ebaf7ed -[JSQMessagesCollectionViewFlowLayout messageBubbleSizeForItemAtIndexPath:] + 301
6 Test 0x000000010ebb02a7 -[JSQMessagesCollectionViewFlowLayout sizeForItemAtIndexPath:] + 71
7 Test 0x000000010ebc5c93 -[JSQMessagesViewController collectionView:layout:sizeForItemAtIndexPath:] + 131
8 UIKit 0x00000001116369be -[UICollectionViewFlowLayout _getSizingInfos] + 988
9 UIKit 0x0000000111637839 -[UICollectionViewFlowLayout _fetchItemsInfoForRect:] + 526
10 UIKit 0x00000001116332b7 -[UICollectionViewFlowLayout collectionViewContentSize] + 66
11 Test 0x000000010ebc2d85 -[JSQMessagesViewController scrollToBottomAnimated:] + 325
12 Test 0x000000010ebc2c34 -[JSQMessagesViewController finishReceivingMessageAnimated:] + 388
13 Test 0x000000010ebc2aa0 -[JSQMessagesViewController finishReceivingMessage] + 48
14 Test 0x000000010ebfaac3 -[XBMessageViewController loadDataToTable] + 1507
15 Test 0x000000010ebf9be9 -[XBMessageViewController viewDidLoad] + 73
16 Test 0x000000010ead0760 -[ViewController viewDidLoad] + 96
17 UIKit 0x0000000111104580 -[UIViewController loadViewIfRequired] + 738
18 UIKit 0x000000011110477e -[UIViewController view] + 27
19 UIKit 0x0000000111023509 -[UIWindow addRootViewControllerViewIfPossible] + 58
20 UIKit 0x00000001110238a1 -[UIWindow _setHidden:forced:] + 247
21 UIKit 0x000000011102ff8c -[UIWindow makeKeyAndVisible] + 42
22 UIKit 0x0000000110fda0c2 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2732
23 UIKit 0x0000000110fdce3e -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
24 UIKit 0x0000000110fdbd35 -[UIApplication workspaceDidEndTransaction:] + 179
25 FrontBoardServices 0x0000000115aab243 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
26 CoreFoundation 0x000000011253fc7c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
27 CoreFoundation 0x00000001125359c5 __CFRunLoopDoBlocks + 341
28 CoreFoundation 0x0000000112535183 __CFRunLoopRun + 851
29 CoreFoundation 0x0000000112534bc6 CFRunLoopRunSpecific + 470
30 UIKit 0x0000000110fdb7a2 -[UIApplication _run] + 413
31 UIKit 0x0000000110fde580 UIApplicationMain + 1282
32 Test 0x000000010ead06d3 main + 115
33 libdyld.dylib 0x0000000112b3c145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I understand it says, that I haven't implemented the function messageHash in Class XBMessage , but the same code works fine in the sample code that I download from Github. Kindly help me to solve this error.

The library that XBChatModule is based on has since been updated. If you look at the history of the protocol that XBMessage conforms to: https://github.com/jessesquires/JSQMessagesViewController/commits/develop/JSQMessagesViewController/Model/JSQMessageData.h you can see that the method messageHash has been made required since the XBChatModule was written.
As such, I recommend contacting the developers of XBChatModule and get them to update their code or, alternatively, implement your own messageHash method.

Related

"unrecognized selector sent to instance" error occured from AppLovin SDK for iOS

I'm trying the following steps to integrate AppLovin for iOS, but an error occurred Do you have any idea how to resolve this issue?
Download AppLovin SDK for iOS and drag AppLovinSDK.framework to my project.
Add dependent frameworks.
AdSupport
AVFoundation
CoreGraphics
CoreMedia
CoreTelephony
StoreKit (NEW)
SystemConfiguration
UIKit
WebKit (OPTIONAL)
Add my AppLoin SDK Key to info.plist.
Add initialize snippets to AppDelegate.m.
#import <AppLovinSDK/AppLovinSDK.h>
// ...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[ALSdk initializeSdk];
return YES;
}
Add snippets to display ad to ViewController.m.
#import <AppLovinSDK/AppLovinSDK.h>
// ...
- (void)viewDidLoad {
[super viewDidLoad];
if([ALInterstitialAd isReadyForDisplay]){
[ALInterstitialAd show];
}
else{
NSLog(#"Failed");
}
}
Run the application and an error occur with the following stacktraces:
2017-01-03 11:09:58.437 AppLovinSample[80329:1731987] -[NSTaggedPointerString al_containsSubstring:]: unrecognized selector sent to instance 0xa0045564954414e6
2017-01-03 11:09:58.458 AppLovinSample[80329:1731987] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString al_containsSubstring:]: unrecognized selector sent to instance 0xa0045564954414e6'
*** First throw call stack:
(
0 CoreFoundation 0x000000010a02c34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000109a8d21e objc_exception_throw + 48
2 CoreFoundation 0x000000010a09bf34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000109fb1c15 ___forwarding___ + 1013
4 CoreFoundation 0x0000000109fb1798 _CF_forwarding_prep_0 + 120
5 AppLovinSample 0x0000000106834ac0 -[ALSettingsManager loadFromUserSettings:] + 1295
6 AppLovinSample 0x00000001068327f4 -[ALSdk(Private) initWithKey:usingSettings:] + 1446
7 AppLovinSample 0x0000000106831799 +[ALSdk sharedWithKey:settings:] + 181
8 AppLovinSample 0x00000001068314d7 +[ALSdk shared] + 120
9 AppLovinSample 0x000000010683143a +[ALSdk initializeSdk] + 31
10 AppLovinSample 0x00000001067fe75c -[AppDelegate application:didFinishLaunchingWithOptions:] + 92
11 UIKit 0x0000000106fbb68e -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 290
12 UIKit 0x0000000106fbd013 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4236
13 UIKit 0x0000000106fc33b9 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
14 UIKit 0x0000000106fc0539 -[UIApplication workspaceDidEndTransaction:] + 188
15 FrontBoardServices 0x000000011192576b __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
16 FrontBoardServices 0x00000001119255e4 -[FBSSerialQueue _performNext] + 189
17 FrontBoardServices 0x000000011192596d -[FBSSerialQueue _performNextFromRunLoopSource] + 45
18 CoreFoundation 0x0000000109fd1311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 CoreFoundation 0x0000000109fb659c __CFRunLoopDoSources0 + 556
20 CoreFoundation 0x0000000109fb5a86 __CFRunLoopRun + 918
21 CoreFoundation 0x0000000109fb5494 CFRunLoopRunSpecific + 420
22 UIKit 0x0000000106fbedb6 -[UIApplication _run] + 434
23 UIKit 0x0000000106fc4f34 UIApplicationMain + 159
24 AppLovinSample 0x00000001067fe9ef main + 111
25 libdyld.dylib 0x000000010e70a68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Here is the documentation that how to integrate AppLovin SDK for iOS. (It should be logged in.)
I did not realize some sentence in the official documentation. In order to resolve this issue, I needed to enable Xcode Flags.
Enable Xcode Flags
The -ObjC flag must be added for static libraries (such as our SDK) to run correctly.

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.

ABPeoplePickerNavigationController crashed while presentviewcontroller

Some one help me to fix this crash issue. I am not able to get the root cause of it.
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
[self presentViewController:picker animated:YES completion:nil];
And I am getting the below crash, not sure why,
-[ABPeoplePickerNavigationController masterViewController]: unrecognized selector sent to instance 0xdd8cd40
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ABPeoplePickerNavigationController masterViewController]: unrecognized selector sent to instance 0xdd8cd40'
*** First throw call stack:
(
0 CoreFoundation 0x03b5e5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x031f28b6 objc_exception_throw + 44
2 CoreFoundation 0x03bfb903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x03b4e90b ___forwarding___ + 1019
4 CoreFoundation 0x03b4e4ee _CF_forwarding_prep_0 + 14
5 UIKit 0x0271f544 -[UISearchDisplayController _areSearchContentsSplitViewMaster] + 63
6 UIKit 0x0271f6ac -[UISearchDisplayController _configureNewSearchBar] + 307
7 UIKit 0x0271ee63 -[UISearchDisplayController initWithSearchBar:contentsController:searchResultsTableViewStyle:] + 121
8 UIKit 0x0271ede5 -[UISearchDisplayController initWithSearchBar:contentsController:] + 55
9 AddressBookUI 0x03dffe5e -[ABMembersController contentView] + 1223
10 AddressBookUI 0x03e05d3e -[ABMembersViewController updateView] + 57
11 AddressBookUI 0x03e058b0 -[ABMembersViewController loadView] + 36
12 UIKit 0x0249d73e -[UIViewController loadViewIfRequired] + 78
13 UIKit 0x024c31a5 -[UINavigationController _layoutViewController:] + 39
14 UIKit 0x024c36bb -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 235
15 UIKit 0x024c37b3 -[UINavigationController _startTransition:fromViewController:toViewController:] + 78
16 UIKit 0x024c472c -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
17 UIKit 0x024c5349 -[UINavigationController __viewWillLayoutSubviews] + 57
18 UIKit 0x025fe39d -[UILayoutContainerView layoutSubviews] + 213
19 UIKit 0x024c1592 __53-[UINavigationController setNeedsDeferredTransition:]_block_invoke + 45
20 UIKit 0x023a6d33 ___afterCACommitHandler_block_invoke + 15
21 UIKit 0x023a6cde _applyBlockToCFArrayCopiedToStack + 403
22 UIKit 0x023a6b0a _afterCACommitHandler + 532
23 CoreFoundation 0x03b2653e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
24 CoreFoundation 0x03b2648f __CFRunLoopDoObservers + 399
25 CoreFoundation 0x03b043b4 __CFRunLoopRun + 1076
26 CoreFoundation 0x03b03b33 CFRunLoopRunSpecific + 467
27 CoreFoundation 0x03b0394b CFRunLoopRunInMode + 123
28 GraphicsServices 0x04df39d7 GSEventRunModal + 192
29 GraphicsServices 0x04df37fe GSEventRun + 104
30 UIKit 0x0238a94b UIApplicationMain + 1225
31 ShowRoomPrive 0x0026dfd5 main + 181
32 ShowRoomPrive 0x00002ba5 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
use below code i think you had not added delegate and may this help you..
ABPeoplePickerNavigationController *picker =
[[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentViewController:picker animated:YES completion:nil];
or go through this url its will give you step by tutorial how to use it
http://yuvarajmanickam.wordpress.com/2012/09/19/get-contact-number-from-abpeoplepickernavigationcontroller-ios-apps/
or with apple documentation it is show helpfull
https://developer.apple.com/library/ios/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Chapters/QuickStart.html

Crash attempting to set delegate of textfield

I have a lot of textfields and what I am trying to make them do is dismiss when the return key is used. In order for this to work you need to set the delegate of each textfield to self, like this [textfield setDelegate: self];. I have over 50 textfields in my project and in order to make it so they all dismiss I have to copy that line of code for each textfield. In the example below I used a for loop to try to shrink this down, but my project crashes and gives me this error when I try. Can someone tell me what im doing wrong and how i can fix this?
//.h
#interface InsertScheduleCGPS : UIViewController <UITextFieldDelegate>{
NSArray *Dayh;
IBOutlet UITextField *Day11;
}
#property(nonatomic, assign) id<UITextFieldDelegate> delegate;
#property (nonatomic,strong) NSArray *Dayh;
.
//.m
- (void)viewDidLoad
{
[super viewDidLoad];
Dayh = [NSArray arrayWithObjects:#"Day11", nil];
NSLog(#"euf");
for(int i=0; i<[self.Dayh count]; i++) {
NSLog(#"dd%#",[self.Dayh objectAtIndex:i]);
[[self.Dayh objectAtIndex:i] setDelegate: self];
}
- (BOOL)textFieldShouldReturn:(UITextField *)Day11 {
[[self view] endEditing:YES];
return NO;
}
ERROR:
2014-01-18 19:15:26.712 Swepple[64912:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString setDelegate:]: unrecognized selector sent to instance 0x144ec'
*** First throw call stack:
(
0 CoreFoundation 0x0183b5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x015be8b6 objc_exception_throw + 44
2 CoreFoundation 0x018d8903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0182b90b ___forwarding___ + 1019
4 CoreFoundation 0x0182b4ee _CF_forwarding_prep_0 + 14
5 Swepple 0x0000bbd6 -[InsertScheduleCGPS viewDidLoad] + 4262
6 UIKit 0x00440318 -[UIViewController loadViewIfRequired] + 696
7 UIKit 0x004405b4 -[UIViewController view] + 35
8 UIKit 0x0044f361 -[UIViewController viewControllerForRotation] + 63
9 UIKit 0x00446f00 -[UIViewController _visibleView] + 84
10 UIKit 0x006d511a -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 5199
11 UIKit 0x0044c0fc -[UIViewController presentViewController:withTransition:completion:] + 6433
12 UIKit 0x0044c61f -[UIViewController presentViewController:animated:completion:] + 130
13 UIKit 0x0044c65f -[UIViewController presentModalViewController:animated:] + 56
14 UIKit 0x00870e16 -[UIStoryboardModalSegue perform] + 271
15 UIKit 0x0086107e -[UIStoryboardSegueTemplate _perform:] + 174
16 UIKit 0x00442280 -[UIViewController performSegueWithIdentifier:sender:] + 72
17 Swepple 0x000052d4 -[SecondViewController insert:] + 244
18 libobjc.A.dylib 0x015d0874 -[NSObject performSelector:withObject:withObject:] + 77
19 UIKit 0x0032e0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
20 UIKit 0x0032e04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
21 UIKit 0x004260c1 -[UIControl sendAction:to:forEvent:] + 66
22 UIKit 0x00426484 -[UIControl _sendActionsForEvents:withEvent:] + 577
23 UIKit 0x00425733 -[UIControl touchesEnded:withEvent:] + 641
24 UIKit 0x0036b51d -[UIWindow _sendTouchesForEvent:] + 852
25 UIKit 0x0036c184 -[UIWindow sendEvent:] + 1232
26 UIKit 0x0033fe86 -[UIApplication sendEvent:] + 242
27 UIKit 0x0032a18f _UIApplicationHandleEventQueue + 11421
28 CoreFoundation 0x017c483f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
29 CoreFoundation 0x017c41cb __CFRunLoopDoSources0 + 235
30 CoreFoundation 0x017e129e __CFRunLoopRun + 910
31 CoreFoundation 0x017e0ac3 CFRunLoopRunSpecific + 467
32 CoreFoundation 0x017e08db CFRunLoopRunInMode + 123
33 GraphicsServices 0x037e09e2 GSEventRunModal + 192
34 GraphicsServices 0x037e0809 GSEventRun + 104
35 UIKit 0x0032cd3b UIApplicationMain + 1225
36 Swepple 0x0000e04d main + 141
37 libdyld.dylib 0x01d7c70d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
You probably meant
Dayh = [NSArray arrayWithObjects:Day11, nil];
At present, Dayh is an array containing the string "Day11", not the text field.

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