【发布时间】:2013-07-14 05:46:47
【问题描述】:
我有一个应用程序尝试检索 iAd,如果不成功,则加载 AdMob 广告。它在 iPhone 上完美运行,但在 iPad 上运行时,我得到一个阻止应用程序加载的连续循环。这是一些代码:
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
@try {
NSLog(@"Ad Error, looking for AdMob Ad...");
// Create a view of the standard size at the bottom of the screen.
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
// I know the banner size is incorret for iPad but it's only supposed to run
// on iPad in compatibility mode and changing doesn't help
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = @"XXXXXXX";
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
GADRequest *admobRequest = [GADRequest request];
admobRequest.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID,
nil];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest: admobRequest];
[iAdBanner setHidden: YES];
[bannerView_ setHidden: NO];
}
@catch (NSException *e) {
NSLog(@"Exception: %@", e);
}
@finally {
}
}
NSLog 连续打印出来,应用程序无法加载。
012-02-24 21:58:38.991 TrophyConverter Free[2948:15e03] Ad Error, looking for AdMob Ad...
2012-02-24 21:58:38.992 TrophyConverter Free[2948:15e03] Ad Error, looking for AdMob Ad...
2012-02-24 21:58:38.994 TrophyConverter Free[2948:15e03] Ad Error, looking for AdMob Ad...
有其他人经历过吗?我怎么过来呢?我已经设法使用bool 来停止连续打印日志并加载应用程序,但没有显示广告。
编辑: 删除此行后问题完全消失
[self.view addSubview:bannerView_];
这没有帮助,因为这是添加 AdMob 视图的部分。
我还尝试将构建目标更改为通用应用程序而不是 iPhone 应用程序。这解决了问题,但我不希望它成为通用应用程序,并且我没有为它创建布局。
【问题讨论】:
-
@MyztikJenz 没有错误,一旦达到 [self.view addSubView: bannerView_] 就会一直调用 didFailToReceiveAdWithError。这就像一个永无止境的循环。最终我得到一个 EXC_BAD_ACCESS 并且在调试期间我无法查看 self.view 所以我想这与此有关。我正在使用 ARC,所以没有早期版本或任何东西
-
@MyztikJenz 我有一份来自 Apple 的崩溃日志,如果对你有帮助的话。我注意到你为他们工作:)
-
所以当递归调用此方法时,您是说
error参数为零?将崩溃日志添加到问题中也会有所帮助。 -
@MyztikJenz 对不起,我误解了,NSError 是“Error Domain=ADErrorDomain Code=3”操作无法完成。广告资源不可用“UserInfo=0x8181e20 {ADInternalErrorCode=3, NSLocalizedFailureReason=广告资源不可用}”。我应该如何发布崩溃日志 - 只需将其粘贴到问题中,它很长......?
-
我认为你的崩溃日志不会有帮助......你很可能是由于无限递归炸毁堆栈而崩溃。我没有使用 GADBannerView 的经验,但我敢打赌它看到您使用的是 iPad,但指定的是 iPhone 大小的广告。您要么需要修正广告的尺寸,弄清楚为什么没有可用的广告资源,要么在收到此错误时直接退出而不显示广告。