Crash with iAd only on iOS 7 - weak delegate is bad pointer - ios

I'm getting a strange crash with the iAd error callback. Here is my crash log:
Exception Type: EXC_BAD_ACCESS Code: KERN_INVALID_ADDRESS at 0x2281
0com.apple.main-thread Crashed
0 libobjc.A.dylib objc_retain + 17
1 YouDoodle AdView.m line 265 -[AdContainerView requestGAD]
2 iAd -[ADBannerView _forwardErrorToDelegate:] + 254
3 iAd -[ADBannerView serverBannerViewDidFailToReceiveAdWithError:] + 178
4 iAd -[ADAdSpace setServiceAdSpace:] + 472
5 CoreFoundation __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
6 CoreFoundation _CFXNotificationPost + 1718
7 Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] + 76
8 Foundation -[NSNotificationCenter postNotificationName:object:] + 30
9 iAd -[ADAdSheetProxy _adSheetConnectionLost] + 292
10 ... libdispatch.dylib _dispatch_call_block_and_release + 10
11 libdispatch.dylib _dispatch_client_callout + 22
12 libdispatch.dylib _dispatch_main_queue_callback_4CF$VARIANT$up + 274
13 CoreFoundation __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
14 CoreFoundation __CFRunLoopRun + 1300
15 CoreFoundation CFRunLoopRunSpecific + 522
16 CoreFoundation CFRunLoopRunInMode + 106
17 GraphicsServices GSEventRunModal + 138
18 UIKit UIApplicationMain + 1136
19 YouDoodle
AppDelegate.m line 129
main
http://crashes.to/s/c654d14dcfa
delegate callback for iAd:
- (void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
DLog(#"IAD Failed to load with error %#", error);
self.adBannerContainer.hidden = YES;
if (InternetAvailableWithAlert(NO))
{
if (self.gadAvailable)
{
self.gadBannerContainer.hidden = NO;
}
else
{
[self requestGAD];
}
}
}
- (void) requestGAD
{
GADRequest* request = [[GADRequest alloc] init];
#if TARGET_IPHONE_SIMULATOR
request.testDevices = #[GAD_SIMULATOR_ID];
#endif
self.gadBanner.rootViewController = (self.gadBanner.rootViewController ?: self.viewController);
[self.gadBanner loadRequest:request];
}
The iAd view delegate is a singleton which is never released. Even if it was released, the iAd class delegate property is a weak property so it should auto-nil.
#property (nonatomic, weak) id<ADBannerViewDelegate> delegate;
Ideas?

This was due to setting the Admob SDK root view controller back to itself, when the view controller has been deallocated, this crashes. Admob SDK uses an assign reference instead of weak which is why it crashed.

Related

Application tried to present a nil modal view controller on target in React Native

there
I'm trying to open native modal on iOS in React Native.
The result I wanted was a screen like the one below.
But I got the following error:
Thread 1: "Application tried to present a nil modal view controller on target <UIViewController: 0x7f904f811290>.
I don't know much about object-c, so I searched the internet for it, and eventually asked a question.
How can I solve it?
Here is one of the stack traces:
*** First throw call stack:
(
0 CoreFoundation 0x000000010a5a1bb4 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x000000010a2abbe7 objc_exception_throw + 48
2 UIKitCore 0x000000011b2c5b95 -[UIViewController _presentViewController:withAnimationController:completion:] + 6177
3 UIKitCore 0x000000011b2c6520 __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 98
4 UIKitCore 0x000000011b2c6856 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 519
5 UIKitCore 0x000000011b2c647e -[UIViewController _presentViewController:animated:completion:] + 173
6 UIKitCore 0x000000011b2c690c -[UIViewController presentViewController:animated:completion:] + 155
7 Awesome 0x0000000100243d7b __19-[Buzzvil openFeed]_block_invoke + 203
8 libdispatch.dylib 0x000000010e7d6a28 _dispatch_call_block_and_release + 12
9 libdispatch.dylib 0x000000010e7d7c0c _dispatch_client_callout + 8
10 libdispatch.dylib 0x000000010e7e6376 _dispatch_main_queue_callback_4CF + 1195
11 CoreFoundation 0x000000010a50f85d __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
12 CoreFoundation 0x000000010a50a0ba __CFRunLoopRun + 2772
13 CoreFoundation 0x000000010a509103 CFRunLoopRunSpecific + 567
14 GraphicsServices 0x000000011316ccd3 GSEventRunModal + 139
15 UIKitCore 0x000000011ba6be63 -[UIApplication _run] + 928
16 UIKitCore 0x000000011ba70a53 UIApplicationMain + 101
17 Awesome 0x0000000100244518 main + 104
18 dyld 0x00000001089d5e1e start_sim + 10
19 ??? 0x00000002005f64fe 0x0 + 8596186366
20 ??? 0x0000000000000003 0x0 + 3
)
Here is my problematic code ( Buzzvil.m )
#import "Buzzvil.h"
#import <React/RCTLog.h>
#import BuzzAdBenefit;
#interface Buzzvil ()
#property (nonatomic, strong, readonly) BZVBuzzAdFeed *buzzAdFeed;
#end
#implementation Buzzvil
RCT_EXPORT_MODULE();
- (void) viewDidLoad {
[super viewDidLoad];
_buzzAdFeed = [BZVBuzzAdFeed feedWithBlock:^(BZVBuzzAdFeedBuilder * _Nonnull builder) {}];
}
RCT_EXPORT_METHOD(logEvent:(NSString *)name location:(NSString *)location)
{
RCTLogInfo(#"fire event xocde log %# at %#", name, location);
}
RCT_EXPORT_METHOD(messageEvent:(RCTResponseSenderBlock)callback)
{
callback(#[#"hello from native ios"]);
}
RCT_EXPORT_METHOD(setUserEvent:(NSString *)userId gender:(NSString *)gender birth:(NSString *)birth)
{
RCTLogInfo(#"id= %# <> gender= %# <> birth= %#", userId, gender, birth);
NSString *male = #"M";
[BuzzAdBenefit loginWithBlock:^(BZVLoginRequestBuilder * _Nonnull builder) {
builder.userId = userId;
builder.birthYear = [birth intValue];
builder.gender = [gender isEqualToString:male] ? BZVUserGenderMale : BZVUserGenderFemale;
} onSuccess:^{
RCTLogInfo(#"on Success!!");
} onFailure:^(NSError * _Nonnull error) {
RCTLogInfo(#"on Error!!");
}];
}
// An error occurs when the function below is executed.
RCT_EXPORT_METHOD(openFeed)
{
dispatch_async(dispatch_get_main_queue(), ^{
UIViewController *rootviewcontroller= [UIApplication sharedApplication].keyWindow.rootViewController;
BZVFeedViewController *feedViewController = [self->_buzzAdFeed viewController];
[rootviewcontroller presentViewController:feedViewController animated:YES completion:nil];
});
}
#end
and here is Buzzvil.h file
#import <React/RCTBridgeModule.h>
#interface Buzzvil : UIViewController<RCTBridgeModule>
#property(nonatomic, strong) UIViewController *rootViewController;
#end

EXC_BAD_ACCESS KERN_INVALID_ADDRESS performLoginDelegateQueue in iOS

crashlytics shows me a crash like below. Why does this error occur?How can I overcome this crash ? I updated my question in code part
Related code part :
-(void)loginUser:(id)delegate returnSelector:(SEL)selector
{
if (delegate != nil) {
LoginDelegate* loginDelegate = [[LoginDelegate alloc] init];
loginDelegate.returnDelegate = delegate;
loginDelegate.returnSelector = selector;
[self.loginDelegateQueue addObject:loginDelegate];
}
.....
....
[self performLoginDelegateQueue];
}
- (void)performLoginDelegateQueue
{
for (LoginDelegate* loginDelegate in self.loginDelegateQueue) {
[loginDelegate.returnDelegate performSelector:loginDelegate.returnSelector];
}
[self clearLoginDelegateQueue];
}
Crashlytics Report :
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x1835040b0 objc_retain + 16
1 MyApp 0x1000e66d8 -[UserController performLoginDelegateQueue] (UserController.m:135)
2 MyApp 0x1000e6180 __43-[UserController loginUser:returnSelector:]_block_invoke (UserController.m:63)
3 libdispatch.dylib 0x1838d1630 _dispatch_call_block_and_release + 24
4 libdispatch.dylib 0x1838d15f0 _dispatch_client_callout + 16
5 libdispatch.dylib 0x1838d6cf8 _dispatch_main_queue_callback_4CF + 1844
6 CoreFoundation 0x183e34bb0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
7 CoreFoundation 0x183e32a18 __CFRunLoopRun + 1628
8 CoreFoundation 0x183d61680 CFRunLoopRunSpecific + 384
9 GraphicsServices 0x185270088 GSEventRunModal + 180
10 UIKit 0x188bd8d90 UIApplicationMain + 204
11 MyApp 0x1000bd734 main (main.m:16)
12 libdispatch.dylib 0x1839028b8 (Missing)
LoginDelegate.h
#interface LoginDelegate : NSObject
#property (unsafe_unretained) id returnDelegate;
#property (unsafe_unretained) SEL returnSelector;
#end

How to solve crash in my iOS Application

While I am testing my iOS application its getting crashed at some point. the crash log as follows can any one please suggest me what might be the reasons to crash. and how can i easily understand where crash is occurs from this crash log data
Thread 0 Crashed:
0 libobjc.A.dylib 0x0000000192f881d0 objc_msgSend + 16
1 UIKit 0x0000000189c7b2c8 -[_UIModalItemsCoordinator _notifyDelegateModalItem:tappedButtonAtIndex:] + 120
2 UIKit 0x0000000189c7b1e8 -[_UIModalItemAlertContentView tableView:didSelectRowAtIndexPath:] + 984
3 UIKit 0x0000000189b6d794 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1260
4 UIKit 0x0000000189c2e230 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 236
5 UIKit 0x0000000189ac246c _applyBlockToCFArrayCopiedToStack + 352
6 UIKit 0x0000000189a2e4a0 _afterCACommitHandler + 500
7 CoreFoundation 0x0000000186a330a4 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 28
8 CoreFoundation 0x0000000186a3032c __CFRunLoopDoObservers + 368
9 CoreFoundation 0x0000000186a306b8 __CFRunLoopRun + 760
10 CoreFoundation 0x00000001869716cc CFRunLoopRunSpecific + 448
11 GraphicsServices 0x000000018c655c08 GSEventRunModal + 164
12 UIKit 0x0000000189aa2fd8 UIApplicationMain + 1152
13 whirlpool-minerva 0x0000000100047834 0x100024000 + 145460
14 libdyld.dylib 0x000000019356ba9c start + 0
A delegate of UIAlertView is deallocated before the alert is dismissed.
If you have an object that is set to be a delegate of UIAlertView and the object may 'die' at some point of app execution (possibly when alert is on screen), then you must set alert view's delegate property to nil in -dealloc method. You have to save a reference to the created alert.
Simple example:
#property (nonatomic, strong) UIAlertView *alert;
...
self.alert = [[UIAlertView alloc] initWith... delegate:self ...];
[self.alert show];
...
- (void)dealloc {
self.alert.delegate = nil;
}

Low memory warning causes a crash on iOS5 - unloadViewForced

I have been able to replicate a low-memory crash on iOS devices that are running iOS5. Every time the stack trace points to the same place, so I know exactly where the problem is. Unfortunately I don't know how to fix it. As you can see below, the crash occurs when CatViewController receives a memory warning. At that point its view gets forcibly unloaded, then the crash happens:
0 libobjc.A.dylib 0x37174f7e objc_msgSend + 22
1 UIKit 0x317eab66 -[UIViewController unloadViewForced:] + 130
2 UIKit 0x31932492 -[UIViewController purgeMemoryForReason:] + 58
3 MyApp 0x001353c0 -[CatViewController didReceiveMemoryWarning] (CatViewController.m:89)
4 Foundation 0x339e34f8 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 12
5 CoreFoundation 0x35178540 ___CFXNotificationPost_block_invoke_0 + 64
6 CoreFoundation 0x35104090 _CFXNotificationPost + 1400
7 Foundation 0x339573e4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 60
8 Foundation 0x33958c14 -[NSNotificationCenter postNotificationName:object:] + 24
9 UIKit 0x318fd26a -[UIApplication _performMemoryWarning] + 74
10 UIKit 0x318fd364 -[UIApplication _receivedMemoryNotification] + 168
11 libdispatch.dylib 0x37ae6252 _dispatch_source_invoke + 510
12 libdispatch.dylib 0x37ae3b1e _dispatch_queue_invoke$VARIANT$up + 42
13 libdispatch.dylib 0x37ae3e64 _dispatch_main_queue_callback_4CF$VARIANT$up + 152
14 CoreFoundation 0x3517f2a6 __CFRunLoopRun + 1262
15 CoreFoundation 0x3510249e CFRunLoopRunSpecific + 294
16 CoreFoundation 0x35102366 CFRunLoopRunInMode + 98
17 GraphicsServices 0x3476d432 GSEventRunModal + 130
18 UIKit 0x31779e76 UIApplicationMain + 1074
19 MyApp 0x00087142 main (main.m:16)
20 MyApp 0x000870c8 start + 32
So I believe this has something to do with the way the view is getting unloaded on iOS5. This view controller is not removing itself from any notifications, so this solution doesn't work. Line 89 of CatViewController is just this:
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; //this is line 89
}
And viewDidUnload just looks like this:
- (void)viewDidUnload {
[self setBackgroundView:nil];
[self setContentView:nil];
[self setSomeScrollView:nil];
[super viewDidUnload];
}
Any ideas on how I can handle this gracefully without crashing?
EDIT: Here's more info on another crash report:
0 CoreFoundation 0x351ac88f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x3717a259 objc_exception_throw + 33
2 CoreFoundation 0x351afa9b -[NSObject doesNotRecognizeSelector:] + 175
3 CoreFoundation 0x351ae915 ___forwarding___ + 301
4 CoreFoundation 0x35109650 _CF_forwarding_prep_0 + 48
5 UIKit 0x317eabdf -[UIViewController unloadViewForced:] + 251
6 UIKit 0x31932499 -[UIViewController purgeMemoryForReason:] + 65
7 MyApp 0x000d541b -[CatViewController didReceiveMemoryWarning] (CatViewController.m:96)
Your app is not crashing because it is out of memory. In your crash report, you can see that the exception thrown was actually [NSObject doesNotRecognizeSelector:].
Firstly, you should move those set to nil statements to didReceiveMemoryWarning; this is the preferred method since viewDidUnload is no longer supported in iOS 6.
Secondly, to find your crash, step through those statements where you set your properties to nil and make sure none of those cause the crash. Note that you will only have methods with those signatures (self set<propertyName>:]) if those variables are declared as properties, not as mere instance variables.

Crash UIScrollView EXC_BAD_ACCESS

I'm having trouble to diagnostic a crash with UIScrollView
UIKit
-[UIScrollView setContentOffset:]
Exception Type: EXC_BAD_ACCESS Code KERN_INVALID_ADDRESS at 0xe0000008
com.apple.main-thread Crashed
0 libobjc.A.dylib objc_msgSend + 15
1 UIKit -[UIScrollView setContentOffset:] + 618
2 UIKit -[UITableView setContentOffset:] + 330
3 UIKit -[UIScrollView(Static) _adjustContentOffsetIfNecessary] + 1474
4 UIKit -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 414
5 UIKit -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:] + 30
6 UIKit -[UIScrollView removeFromSuperview] + 30
7 ... UIKit -[UIView dealloc] + 296
8 UIKit -[UIView dealloc] + 296
9 libobjc.A.dylib (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 168
10 CoreFoundation _CFAutoreleasePoolPop + 16
11 CoreFoundation __CFRunLoopRun + 1296
12 CoreFoundation CFRunLoopRunSpecific + 356
13 CoreFoundation CFRunLoopRunInMode + 104
14 GraphicsServices GSEventRunModal + 74
15 UIKit UIApplicationMain + 1120
16 iTV Shows main.m line 12
I had the same problem. Setting the TableView and ScrollView delegates (or any other delegates that you might have) to nil in the dealloc method solved the problem.
- (void)dealloc {
self.tableView.delegate = nil;
self.tableView.dataSource = nil;
}
Its hard to give a concrete answer without seeing your code, but the iOS Debugging Magic technical note is always a great resource with tips for debugging crashes.
Technical Note TN2239: iOS Debugging Magic

Resources