【发布时间】:2014-04-26 06:30:01
【问题描述】:
当我的应用程序处于开发阶段时,iAds 效果很好。每隔 30 秒,我就会接到“bannerViewDidLoadAd”或“didFailToReceiveAdWithError”的电话,我准备应用程序来处理任一回调。我得到绿色复选标记“您已连接到 iAd 的应用网络”和其他测试广告。
现在该应用已上线,它只会收到“didFailToReceiveAdWithError”并且永远不会加载广告。 我在插入 Xcode Organizer Console 的手机上运行已发布的应用程序版本,我看到在“didFailToReceiveAdWithError”中打印的 NSLog
虽然 iAd 门户没有显示任何请求,但它列出了 0 个请求。
我已经使用开发配置文件从 XCode 再次将它构建到我的手机中,并且它再次正常工作。我删除了该应用,关闭了手机,退出了我的 iTunes Apple ID,然后从 App Store 重新下载了该应用,但每次广告仍然失败。
我是这样对广告进行编码的:
在我的 rootViewController 中,用户选择开始一个新游戏,我为新视图设置动画:
UIViewController *nextController = [[GamePlayViewController alloc] initWithNibName:@"GamePlayView" bundle:nil];
[nextController performSelector:@selector(setDelegate:) withObject:self];
nextController.view.frame = CGRectMake(0, 570, 320, 568);
[self.view addSubview:nextController.view];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.23];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
nextController.view.frame = CGRectMake(0, 0, 320, 568);
[UIView commitAnimations];
temporaryController = nextController;
GamePlayViewController.h 包括:
- #import <iAd/iAd.h>
- @interface GamePlayViewController : UIViewController <ADBannerViewDelegate, UIDocumentInteractionControllerDelegate> {
GamePlayViewController.m 包括:
- ADBannerView *_bannerView;
一旦用户进入 GamePlayViewController.m,就会在 viewDidLoad 中触发一个动画,一旦该动画完成,就会调用一个广告:
if ([ADBannerView instancesRespondToSelector:@selector(initWithAdType:)]) {
_bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
} else {
_bannerView = [[ADBannerView alloc] init];
}
_bannerView.delegate = self;
[self.view bringSubviewToFront:_bannerView];
}
除了 iAds 的回调方法之外,这就是它的全部内容。
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(@"ad loaded!");
_bannerView.hidden = NO;
[self layoutAnimated:YES];
}
- (void)layoutAnimated:(BOOL)animated
{
// As of iOS 6.0, the banner will automatically resize itself based on its width.
// To support iOS 5.0 however, we continue to set the currentContentSizeIdentifier appropriately.
CGRect contentFrame = self.view.bounds;
if (contentFrame.size.width < contentFrame.size.height) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
CGRect bannerFrame = _bannerView.frame;
if (_bannerView.bannerLoaded) {
bannerFrame.origin.y = 0;
} else {
bannerFrame.origin.y = contentFrame.size.height;
}
[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
_contentView.frame = contentFrame;
[_contentView layoutIfNeeded];
_bannerView.frame = bannerFrame;
[self.view addSubview:_bannerView];
}];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(@"ad failed!");
_bannerView.hidden = YES;
}
也许我做错了什么,或者我应该在 rootViewController 本身上放置广告,但这段代码在测试 iAd 上效果很好,所以我不确定为什么它不适用于应用程序的 App Store 版本。
感谢您的帮助!
【问题讨论】:
标签: ios iphone objective-c iad