我遇到了一个奇怪的崩溃,iAd错误回调。这是我的崩溃日志:
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
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];
}
iAd 视图委托是一个永远不会发布的单一实例。即使它已释放,iAd 类委托属性也是一个弱属性,因此它应该自动 nil。
@property (nonatomic, weak) id<ADBannerViewDelegate> delegate;
想法?
这是因为将
Admob SDK 根视图控制器设置回自身,当视图控制器解除分配后,此操作会崩溃。Admob SDK 使用分配引用而不是弱引用,这就是它崩溃的原因。