我已经完成了我的第一个应用程序。我在上面放了 iAd 横幅。以及来自 iTunnes Connect 的活跃 iAd。
我从本教程中学会了添加 iAd。 http://www.youtube.com/watch?v=fP2ijcXbCz4
我需要在我的代码中添加其他东西吗?广告会自动显示吗?
@interface TOCGMainViewController () <ADBannerViewDelegate>
@property (strong, nonatomic) IBOutlet ADBannerView *iAdBanner;
@end
@implementation TOCGMainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if ([[ UIScreen mainScreen ] bounds ].size.height == 568 ) {
nibNameOrNil = [NSString stringWithFormat:@"%@_568", nibNameOrNil ?: @"TOCGMainViewController"];
}
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
}
if ([ADBannerView instancesRespondToSelector:@selector(initWithAdType:)]) {
self.iAdBanner = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
} else {
self.iAdBanner = [[ADBannerView alloc] init];
}
return self;
}
... ... ...
#pragma mark - ADBannerViewDelegate
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSUserDefaults *saveApp = [NSUserDefaults standardUserDefaults];
bool saved = [saveApp boolForKey:k_Save];
if (!saved) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
} else {
banner.hidden = YES;
[banner removeFromSuperview];
banner = nil;
banner.delegate = nil;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
@end
最佳答案
要测试您的 iAd 代码,您只需在模拟器或您的设备上运行应用即可。如果您正确设置了所有内容,您应该会看到一个指示这一点的演示横幅。当应用程序进入商店时,这将被实际广告取代。
关于ios - 有什么可以激活 iAd 的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24059083/