removeObserver crashing my app even though appears to be balanced with addObserver - ios

So I have a class, CustomCell : UITableViewCell with a single addObserver:forKeyPath:options:context: method, called in -awakeFromNib, and a single removeObserver:forKeyPath:context: method, called in -dealloc.
CustomCell.m
static void * const MyClassKVOContext = (void*)&MyClassKVOContext; // unique context
-(void)awakeFromNib
{
[super awakeFromNib];
[self registerAsLocationListener];
}
-(void)registerAsLocationListener
{
if ([self.reuseIdentifier isEqualToString:#"locationcell1"])
{
[[RA_LocationSingleton locationSingleton]
addObserver:self
forKeyPath:#"currentLocation"
options:NSKeyValueObservingOptionNew
context:MyClassKVOContext];
NSLog(#"Registered for currentLocation");
NSLog(#"self.description: %#", [self description]);
}
}
-(void)dealloc
{
if ([self.reuseIdentifier isEqualToString:#"locationcell1"])
{
NSLog(#"Attempting to deregister");
NSlog(#"self.description: %#", [self description]);
[self removeObserver:self
forKeyPath:#"currentLocation"
context:MyClassKVOContext];
}
// [super dealloc]; called automatically, using ARC
}
I get the following log, after loading the view with these cells, then backing out again (triggering the dealloc)
// load view
2014-09-01 14:27:33.704 Rally[2931:60b] Registered for currentLocation
2014-09-01 14:27:33.705 Rally[2931:60b] self.description: <CustomCell: 0x9afa570; baseClass = UITableViewCell; frame = (0 0; 320 44); autoresize = RM+BM; layer = <CALayer: 0x9afa710>>
// exit from view
2014-09-01 14:27:40.867 Rally[2931:60b] Attempting to deregister
2014-09-01 14:27:40.868 Rally[2931:60b] self.description: <CustomCell: 0x9afa570; baseClass = UITableViewCell; frame = (0 231; 320 44); autoresize = W; layer = <CALayer: 0x9afa710>>
2014-09-01 14:27:40.870 Rally[2931:60b] *** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <CustomCell 0x9afa570> for the key path "currentLocation" from <CustomCell 0x9afa570> because it is not registered as an observer.'
*** First throw call stack:
(
0 CoreFoundation 0x026761e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x023f58e5 objc_exception_throw + 44
2 CoreFoundation 0x02675fbb +[NSException raise:format:] + 139
3 Foundation 0x0204346d -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 538
4 Foundation 0x020431f4 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 105
5 Foundation 0x02043118 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:] + 172
6 Rally 0x00005ac1 -[CustomCell dealloc] + 353
7 UIKit 0x01107b94 -[UIView release] + 89
8 CoreFoundation 0x025f7bf0 CFRelease + 272
9 CoreFoundation 0x0261716e -[__NSArrayM dealloc] + 142
10 libobjc.A.dylib 0x02406692 _ZN11objc_object17sidetable_releaseEb + 268
11 libobjc.A.dylib 0x02405e81 objc_release + 49
12 libobjc.A.dylib 0x02406ce7 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 537
13 CoreFoundation 0x02617878 _CFAutoreleasePoolPop + 24
14 CoreFoundation 0x0261c5d3 __CFRunLoopRun + 1971
15 CoreFoundation 0x0261b9d3 CFRunLoopRunSpecific + 467
16 CoreFoundation 0x0261b7eb CFRunLoopRunInMode + 123
17 GraphicsServices 0x036f85ee GSEventRunModal + 192
18 GraphicsServices 0x036f842b GSEventRun + 104
19 UIKit 0x010b5f9b UIApplicationMain + 1225
20 Rally 0x00006a6d main + 141
21 libdyld.dylib 0x02ef6701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I've double-checked (ctrl+f) that nowhere else are these methods called. So it seems that for any instance, there is precisely one addObserver (with unique context) and precisely one removeObserver (with that context)

Apologies all
Have just spotted my typo:
[self removeObserver:self
forKeyPath:#"currentLocation"
context:MyClassKVOContext];
should be
[[RA_LocationSingleton locationSingleton] removeObserver:self
forKeyPath:#"currentLocation"
context:MyClassKVOContext];

Related

I am getting error at my cellForRowAtIndexPath in tableview after i filter with predicate

[__NSDictionaryM safeObjectAtIndex:]: unrecognized selector sent to instance 0x60800005e060
[__NSDictionaryM safeObjectAtIndex:]: unrecognized selector sent to instance 0x60800005e060 [IssuesViewController-tableView:cellForRowAtIndexPath:]
Assertion failure in -[STCollapseTableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.7.47/UITableView.m:8174
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (; layer = ; contentOffset: {0, 0}; contentSize: {414, 115}>) failed to obtain a cell from its dataSource (; layer = ; contentOffset: {0, 0}; contentSize: {414, 115}>)'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108d8bb0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001087c3141 objc_exception_throw + 48
2 CoreFoundation 0x0000000108d8fcf2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x000000010835d3b6 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 UIKit 0x0000000109aeefcf -[UITableView _configureCellForDisplay:forIndexPath:] + 230
5 UIKit 0x0000000109afa7b8 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 836
6 UIKit 0x0000000109afa9a8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
7 UIKit 0x0000000109acf2e9 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2845
8 UIKit 0x0000000109b0397c -[UITableView _performWithCachedTraitCollection:] + 111
9 UIKit 0x0000000109aeab2a -[UITableView layoutSubviews] + 233
10 UIKit 0x0000000109a5120b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
11 QuartzCore 0x0000000107905904 -[CALayer layoutSublayers] + 146
12 QuartzCore 0x00000001078f9526 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 370
13 QuartzCore 0x00000001078f93a0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
14 QuartzCore 0x0000000107888e92 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
15 QuartzCore 0x00000001078b5130 _ZN2CA11Transaction6commitEv + 468
16 UIKit 0x0000000109987307 _UIApplicationFlushRunLoopCATransactionIfTooLate + 167
17 UIKit 0x000000010a187cab __handleEventQueue + 5843
18 CoreFoundation 0x0000000108d31c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 CoreFoundation 0x0000000108d170cf __CFRunLoopDoSources0 + 527
20 CoreFoundation 0x0000000108d165ff __CFRunLoopRun + 911
21 CoreFoundation 0x0000000108d16016 CFRunLoopRunSpecific + 406
22 GraphicsServices 0x000000010b8eaa24 GSEventRunModal + 62
23 UIKit 0x000000010998e0d4 UIApplicationMain + 159
24 comress 0x000000010626910f main + 111
25 libdyld.dylib 0x000000010b4d765d start + 1)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
This is sample code:
NSArray *postDupe = [[_postsArray valueForKeyPath:#"#unionOfArrays.#allValues"] valueForKeyPath:#"post"];
NSArray *foundArray = nil;
predicate = [NSPredicate predicateWithFormat:#"post_id.stringValue contains [c] %#",#"18586"];
foundArray = [postDupe filteredArrayUsingPredicate:predicate];
long foundIndex = 0;
long count = 0;
for (int i=0; i<foundArray.count; i++)
{
foundIndex = [postDupe indexOfObject: [foundArray objectAtIndex: i]];
//NSLog(#"%# is at index %d", string, index);
}
_filterPostsArray = [_postsArray objectAtIndex:foundIndex];
}
searchActive = YES;
dispatch_async(dispatch_get_main_queue(),^{
[_issuesTable reloadData];
});
Sample Json Data:
<__NSArrayM 0x608000449a80>(
{
14556 = {
newCommentsCount = 0;
post = {
"post_id" = 18609;
seen = 1;
status = 0;
statusWasUpdated = 0;
"updated_on" = "1506061049.023";
};
};
},
)
[__NSDictionaryM safeObjectAtIndex:]: unrecognized selector sent to instance
Looks like you have a dictionary and are treating it like an array.
Run your code in the debugger and examine the values of the variables as you move through your algorithm, this should show you where you go wrong.
Guessing:
The key path in your predicate post_id.stringValue should be post.post_id.stringValue - your dictionary contains a key post whose value is itself a dictionary which has a key post_id.
_filterPostsArray = [_postsArray objectAtIndex:foundIndex] sounds like it is assigning a dictionary to an array. You probably wanted this statement to be in the loop and adding the dictionary as a new element to the array?
HTH

Why UIView's setFrame is not same as UILabel's setFrame

In order to detect the behavior of refresh UI on background thread,I used the third-part library ODUIThreadGuard.
This lib is based on hook UIView's setNeedsLayout、setNeedsDisplay、setNeedsDisplayInRect selector.
When I tested it, I found that UILabel's setFrame: on background thread can be detected but UIView's can't.Who can tell me why?
code:
// ViewController.m
[self.view addSubview:self.testLabel];
[self.view addSubview:self.testView];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
self.testLabel.frame = CGRectMake(20, 20, 100, 100);
});
The above code will be detected but the following will not .
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
self.testView.frame = CGRectMake(20, 20, 100, 100);
});
hook code :
#implementation UIView (ThreadSafeGuard)
+ (void)load {
[DBHookUtil swizzlingInClass:[self class] originalSelector:#selector(setNeedsLayout) swizzledSelector:#selector(db_setNeedsLayout)];
[DBHookUtil swizzlingInClass:[self class] originalSelector:#selector(setNeedsDisplay) swizzledSelector:#selector(db_setNeedsDisplay)];
[DBHookUtil swizzlingInClass:[self class] originalSelector:#selector(setNeedsDisplayInRect:) swizzledSelector:#selector(db_setNeedsDisplayInRect:)];
}
- (void)db_setNeedsLayout {
NSAssert([NSThread isMainThread], #"refresh UI on background thread");
[self db_setNeedsLayout];
}
- (void)db_setNeedsDisplay {
NSAssert([NSThread isMainThread], #"refresh UI on background thread");
[self db_setNeedsDisplay];
}
- (void)db_setNeedsDisplayInRect:(CGRect)rect {
NSAssert([NSThread isMainThread], #"refresh UI on background thread");
[self db_setNeedsDisplayInRect:rect];
}
#end
crash log:
2017-05-15 18:17:40.876 ThreadSafeGuardDemo[50800:19659410] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'refresh UI on background thread'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105181b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000104be6141 objc_exception_throw + 48
2 CoreFoundation 0x0000000105185cf2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x00000001047803b6 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 ThreadSafeGuardDemo 0x0000000104615068 -[UIView(ThreadSafeGuard) db_setNeedsDisplay] + 264
5 UIKit 0x00000001058311f6 -[UILabel setNeedsDisplay] + 55
6 UIKit 0x00000001058279e6 -[UILabel _invalidateAsNeededForNewSize:oldSize:withLinkCheck:] + 336
7 UIKit 0x0000000105827c9f -[UILabel setFrame:] + 76
8 ThreadSafeGuardDemo 0x0000000104614a76 __29-[ViewController viewDidLoad]_block_invoke + 278
9 libdispatch.dylib 0x0000000107f744a6 _dispatch_call_block_and_release + 12
10 libdispatch.dylib 0x0000000107f9d05c _dispatch_client_callout + 8
11 libdispatch.dylib 0x0000000107f7f198 _dispatch_root_queue_drain + 1358
12 libdispatch.dylib 0x0000000107f7ebef _dispatch_worker_thread3 + 123
13 libsystem_pthread.dylib 0x00000001083c3746 _pthread_wqthread + 1299
14 libsystem_pthread.dylib 0x00000001083c3221 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

app is getting crshed showing "UITableView was deallocated while key value observers were still registered with it"

My app getting crashed while navigating back to previous ViewController from a ViewController.
I have registered with observer as:
[tblViewActvityCalender addObserver:self
forKeyPath:#"contentSize"
options:0
context:NULL];
and in delloc() method, I'm removing the observer as:
[tblViewActvityCalender removeObserver:self forKeyPath:#"contentSize"];
but still I'm getting app crashed(mostly in ios 8). What I have done wrong ???Thanks in adavnce..
Crash Log:
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x7ab75400 of class UITableView was deallocated while key value observers were still registered with it. Current observation info: (
Context: 0x0, Property: 0x7a601490>
)'
* First throw call stack:
(
0 CoreFoundation 0x0268f946 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x02318a97 objc_exception_throw + 44
2 CoreFoundation 0x0268f86d +[NSException raise:format:] + 141
3 Foundation 0x01f496d4 NSKVODeallocate + 379
4 UIKit 0x0076459b -[UIView release] + 89
5 UIKit 0x0077537a -[UIView(Hierarchy) removeFromSuperview] + 733
6 UIKit 0x00793399 -[UIScrollView removeFromSuperview] + 84
7 UIKit 0x007679bc -[UIView dealloc] + 483
8 UIKit 0x0076459b -[UIView release] + 89
9 libobjc.A.dylib 0x0232ceb1 objc_release + 65
10 libobjc.A.dylib 0x0232dd32 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 586
11 CoreFoundation 0x02571678 _CFAutoreleasePoolPop + 24
12 CoreFoundation 0x025a876e __CFRunLoopRun + 2270
13 CoreFoundation 0x025a7bcb CFRunLoopRunSpecific + 443
14 CoreFoundation 0x025a79fb CFRunLoopRunInMode + 123
15 GraphicsServices 0x0443824f GSEventRunModal + 192
16 GraphicsServices 0x0443808c GSEventRun + 104
17 UIKit 0x006fa8b6 UIApplicationMain + 1526
18 e-Care 0x0023311d main + 141
19 libdyld.dylib 0x035a8ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Try following, it may work...
Remove observer in viewwilldisappear and also remove table delegates.
If you have any running operation which can effect table content size, then stop it or wait for it before you move back to other screen.
Today I face same issue...
Before remove View Or ViewController You need to remove **tableview detaSource, Delegate and tableview from screen and then after remove screen
just add follow code in your .m file.
-(void)dealloc
{
self.tableView.delegate = nil;
self.tableView.dataSource = nil;
self.tableView removeFromSuperview];
}
I hope it will work for you
I recommend you reading http://nshipster.com/key-value-observing/
In an object, you use
- (void)addObserver:(NSObject *)observer
forKeyPath:(NSString *)keyPath
options:(NSKeyValueObservingOptions)options
context:(void *)context
Therefor to remove the observer you should use (you did it)
removeObserver:forKeyPath:context
However what probably happens is that your UITableView is deallocated before the object (referred as self in your code) is deallocated.
Therefor the crash.
You should ensure that this object unregister before it is deallocated, maybe by doing it within viewDidDisappear

Error EXC_BAD_ACCESS when pressing button

When i press my button, i got a error of access.
the error : Thread 1 : EXC_BAD_ACCESS(code=1,address=0xd0a937db)
TTest.h
#interface TTtest : NSObject
{
UIButton *monBouton ;
UIImage *skin;
}
- (void)initTest :(UIView*)vueDonne;
-(void)test:(id)sender;
TTest.m
- (void)initTest :(UIView*)vueDonne
{
skin = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:#"boutonG" ofType:#"png"]];
monBouton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
monBouton.frame = CGRectMake(50, 50, 45, 50);
[monBouton setImage:skin forState:UIControlStateNormal];
[monBouton addTarget:self action:#selector(test:) forControlEvents:UIControlEventTouchDown];
[vueDonne addSubview: monBouton];
}
-(void)test:(id)sender //didn't work because i have the probleme
{
NSLog(#"test clicked");
}
testViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
TTtest *test =[[TTtest alloc] init];
[test initTest:_testView]; //View of my application
}
EDIT:
If i add monBouton = [[UIButton alloc] init];
I get a problem of SIGABRT
2014-10-26 16:47:22.827 testAsk[2134:a0b] -[CALayerArray test:]: unrecognized selector sent to instance 0xa141ea0
2014-10-26 16:47:22.831 testAsk[2134:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CALayerArray test:]: unrecognized selector sent to instance 0xa141ea0'
*** First throw call stack:
(
0 CoreFoundation 0x017395e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bc8b6 objc_exception_throw + 44
2 CoreFoundation 0x017d6903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172990b ___forwarding___ + 1019
4 CoreFoundation 0x017294ee _CF_forwarding_prep_0 + 14
5 libobjc.A.dylib 0x014ce874 -[NSObject performSelector:withObject:withObject:] + 77
6 UIKit 0x0022c0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
7 UIKit 0x0022c04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8 UIKit 0x003240c1 -[UIControl sendAction:to:forEvent:] + 66
9 UIKit 0x00324484 -[UIControl _sendActionsForEvents:withEvent:] + 577
10 UIKit 0x003231fd -[UIControl touchesBegan:withEvent:] + 254
11 UIKit 0x0026934b -[UIWindow _sendTouchesForEvent:] + 386
12 UIKit 0x0026a184 -[UIWindow sendEvent:] + 1232
13 UIKit 0x0023de86 -[UIApplication sendEvent:] + 242
14 UIKit 0x0022818f _UIApplicationHandleEventQueue + 11421
15 CoreFoundation 0x016c283f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
16 CoreFoundation 0x016c21cb __CFRunLoopDoSources0 + 235
17 CoreFoundation 0x016df29e __CFRunLoopRun + 910
18 CoreFoundation 0x016deac3 CFRunLoopRunSpecific + 467
19 CoreFoundation 0x016de8db CFRunLoopRunInMode + 123
20 GraphicsServices 0x0368e9e2 GSEventRunModal + 192
21 GraphicsServices 0x0368e809 GSEventRun + 104
22 UIKit 0x0022ad3b UIApplicationMain + 1225
23 testAsk 0x000027bd main + 141
24 libdyld.dylib 0x01d75725 start + 0
25 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The reason for the crash is that test object is dealloced when it receives the button action.
TTtest *test =[[TTtest alloc] init]; //dealloced after viewDidLoad
so try to make the test a property and use self.test.
self.test =[[TTtest alloc] init];
Doesn't look like you defined the selector "test"
-(void)test: (id) sender
NSLog(#"test clicked");
}

[GADSlot state]: unrecognized selector sent to instance in iphone

I am new to iOS development.
I am trying to implementing admob ads in iOS in my phonegap app so I googled & found somveadmob without plugin.
after following all procedure,
I got an error MyApp[2388:70b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GADSlot state]: unrecognized selector sent to instance 0x10415920'**
so I google about & found that I have to change other Linker flags. (-ObjC)here
I have tried it but it is not working.
I am getting this error.
this solution also not working for me. [GADSlot state]: unrecognized selector sent to instance
2014-04-21 13:04:41.252 MyApp[2388:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GADSlot state]: unrecognized selector sent to instance 0x10415920'
*** First throw call stack:
(
0 CoreFoundation 0x038a85e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02acb8b6 objc_exception_throw + 44
2 CoreFoundation 0x03945903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0389890b ___forwarding___ + 1019
4 CoreFoundation 0x038984ee _CF_forwarding_prep_0 + 14
5 MyApp 0x0001a01e -[GADSlot isMakingRequest] + 36
6 MyApp 0x00019c7d -[GADSlot setAdType:andReloadRequest:] + 334
7 MyApp 0x00018a5e -[GADBannerView setAdSize:andReload:] + 512
8 MyApp 0x00019052 -[GADBannerView setAdSize:] + 62
9 MyApp 0x00019381 -[GADBannerView initWithAdSize:] + 171
10 MyApp 0x00003e17 -[MainViewController viewDidLoad] + 118
11 UIKit 0x0021c318 -[UIViewController loadViewIfRequired] + 696
12 UIKit 0x0021c5b4 -[UIViewController view] + 35
13 MyApp 0x00002997 -[AppDelegate application:didFinishLaunchingWithOptions:] + 763
14 UIKit 0x00102355 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
15 UIKit 0x00102b95 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
16 UIKit 0x001073a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
17 UIKit 0x0011b87c -[UIApplication handleEvent:withNewEvent:] + 3447
18 UIKit 0x0011bde9 -[UIApplication sendEvent:] + 85
19 UIKit 0x00109025 _UIApplicationHandleEvent + 736
20 GraphicsServices 0x038062f6 _PurpleEventCallback + 776
21 GraphicsServices 0x03805e01 PurpleEventCallback + 46
22 CoreFoundation 0x03823d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
23 CoreFoundation 0x03823a9b __CFRunLoopDoSource1 + 523
24 CoreFoundation 0x0384e77c __CFRunLoopRun + 2156
25 CoreFoundation 0x0384dac3 CFRunLoopRunSpecific + 467
26 CoreFoundation 0x0384d8db CFRunLoopRunInMode + 123
27 UIKit 0x00106add -[UIApplication _run] + 840
28 UIKit 0x00108d3b UIApplicationMain + 1225
29 MyApp 0x000025fd main + 95
30 MyApp 0x00002595 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
please help me out.
main.m
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, #"AppDelegate");//It highlight this line when exception accoure.
[pool release];
return retVal;
}
MainViewController.m
- (void) viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
bannerView_ = [[GADBannerView alloc]initWithAdSize:kGADAdSizeSmartBannerPortrait];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CGFloat screenXPos = (screenWidth/2);
CGFloat screenYPos = screenHeight - kGADAdSizeBanner.size.height;
[bannerView_ setCenter:CGPointMake(screenXPos, screenYPos)];
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
GADRequest *request = [GADRequest request];
request.testing = NO;
[bannerView_ loadRequest:request];
}
I think, GADBannerView is not set up correctly. If you have the source for GADBannerView, examine it and see where the object reference is coming from.U should try to solve this error in that direction.
check ur admob version as well, becoz GDBBannerview is a part of Admob this might accour from that code.
or else try with other (older or newer version) of admob api.

Resources