AdBannerView跨多个视图共享,包括rootviewcontroller,怎么样?

还没有答案,但我有一个更新,似乎已经解决了这个问题,任何想法,为什么现在虽然工作?!

我已经通过为需要显示adBanner的每个课程做了以下工作:

1.在layoutForCurrentOrientation方法中,我添加了以下内容:

adBanner.delegate = self; [self.view addSubview:adBanner]; 

2.在每个类的deAlloc方法中,我删除了以下内容:

 [adBanner removeFromSuperview]; 

原始问题:

我正在尝试使用Apple的iAdSuite示例代码来使用在我所有视图中共享的单个adBanner实例。

示例实现旨在在由rootViewController调用的每个视图上显示adbanner,但是,我希望我的应用在rootViewController视图上也有广告。

在我的修改代码中: –

当我启动应用程序时,即使调用方法来请求广告条幅,rootView上也不会显示条幅。 该类设置为广告的委托,并且委托方法可用。 这些被调用,并且(adBanner.bannerLoaded)的日志是NO。

因为它是一个共享对象,所以如果从rootView切换视图,广告将显示在另一个视图中。 当我返回到rootView时,委托方法日志显示一个横幅被加载,并且被定位在视图的可见部分中。 但横幅是不可见的。

总之,我使用AdAdmin导航项目的iAdSuite示例代码,并尝试使用它,以便在所有视图(包括rootViewController)上显示广告横幅。

任何帮助感激!

我正在使用的代码可以在这里find:

http://developer.apple.com/library/ios/#samplecode/iAdSuite/Introduction/Intro.html

我修改的rootViewController.h:

 #import <UIKit/UIKit.h> #import <iAd/iAd.h> @interface RootViewController : UITableViewController <ADBannerViewDelegate> @end 

我修改了rootViewController.m

 #import "RootViewController.h" #import "TextViewController.h" #import "MapViewController.h" #import "AdBannerNavigationAppDelegate.h" // for SharedAdBannerView macro // #define SharedAdBannerView ((AdBannerNavigationAppDelegate *)[[UIApplication sharedApplication] delegate]).adBanner #import <iAd/iAd.h> @interface RootViewController() // Layout the Ad Banner and Content View to match the current orientation. // The ADBannerView always animates its changes, so generally you should // pass YES for animated, but it makes sense to pass NO in certain circumstances // such as inside of -viewDidLoad. - (void)layoutForCurrentOrientation:(BOOL)animated; // A simple method that creates an ADBannerView // Useful if you need to create the banner view in code // such as when designing a universal binary for iPad - (void)createADBannerView; @end - (void)viewDidLoad { [super viewDidLoad]; [self createADBannerView]; [self layoutForCurrentOrientation:NO]; } - (void)viewDidUnload { ADBannerView *adBanner = SharedAdBannerView; adBanner.delegate = nil; [adBanner removeFromSuperview]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self layoutForCurrentOrientation:NO]; } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [self layoutForCurrentOrientation:YES]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (void)dealloc { ADBannerView *adBanner = SharedAdBannerView; adBanner.delegate = nil; [adBanner removeFromSuperview]; [super dealloc]; } - (void)createADBannerView { ADBannerView *adBanner = SharedAdBannerView; NSString *contentSize; if (&ADBannerContentSizeIdentifierPortrait != nil) { contentSize = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifierLandscape; } else { contentSize = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? ADBannerContentSizeIdentifier320x50 : ADBannerContentSizeIdentifier480x32; } CGRect frame; frame.size = [ADBannerView sizeFromBannerContentSizeIdentifier:contentSize]; frame.origin = CGPointMake(0.0f, CGRectGetMaxY(self.view.bounds)); adBanner.frame = frame; adBanner.delegate = self; adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin; adBanner.requiredContentSizeIdentifiers = (&ADBannerContentSizeIdentifierPortrait != nil) ? [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil] : [NSSet setWithObjects:ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil]; [self.view addSubview:adBanner]; } - (void)layoutForCurrentOrientation:(BOOL)animated { ADBannerView *adBanner = SharedAdBannerView; CGFloat animationDuration = animated ? 0.2f : 0.0f; CGRect contentFrame = self.view.bounds; CGPoint bannerOrigin = CGPointMake(CGRectGetMinX(contentFrame), CGRectGetMaxY(contentFrame)); CGFloat bannerHeight = 0.0f; if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) adBanner.currentContentSizeIdentifier = (&ADBannerContentSizeIdentifierLandscape != nil) ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifier480x32; else adBanner.currentContentSizeIdentifier = (&ADBannerContentSizeIdentifierPortrait != nil) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifier320x50; bannerHeight = adBanner.bounds.size.height; if (adBanner.bannerLoaded) { contentFrame.size.height -= bannerHeight; bannerOrigin.y -= bannerHeight; } else { bannerOrigin.y += bannerHeight; } [UIView animateWithDuration:animationDuration animations:^{ adBanner.frame = CGRectMake(bannerOrigin.x, bannerOrigin.y, adBanner.frame.size.width, adBanner.frame.size.height); }]; NSLog(@"%f is y pos, height=%f, is it loaded...%@", adBanner.frame.origin.y, adBanner.frame.size.height, adBanner.bannerLoaded?@"YES":@"NO"); } - (void)bannerViewDidLoadAd:(ADBannerView *)banner { [self layoutForCurrentOrientation:YES]; } - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error { [self layoutForCurrentOrientation:YES]; } - (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave { return YES; } - (void)bannerViewActionDidFinish:(ADBannerView *)banner { } @end