如何以仅在 AppDelegate 中实现并且可以在所有屏幕中使用的方式实现 iAd。
我将代码放在 appDelegate 中。我还需要在每个视图控制器中为它编写代码吗?
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self addiAd];
NSLog(@"window subview : %@",self.window.subviews); //Here it shows no subview
return YES;
}
-(void)addiAd
{
self.adView.delegate = self;
self.adView.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierLandscape,ADBannerContentSizeIdentifierPortrait, nil];
self.adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
[self setBannerFrame:orientation];
self.adView = [[ADBannerView alloc] init];
self.adView.frame = CGRectMake(0, 938, 768, 66);
[self.window addSubview:self.adView];
}
-(void)removeiAd
{
[self.adView removeFromSuperview];
}
-(void)setBannerFrame:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[self.adView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierLandscape];
self.adView.frame = CGRectMake(0, 634, 320, 50);
}
else {
[self.adView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];
self.adView.frame = CGRectMake(0, 890, 480, 32);
}
}
它的所有委托方法也在 AppDelegate.m 中实现
我的下一步应该是什么?我做错了什么或错过了什么?