我已经实施了AdMob&一切似乎都有效,
但我想知道,我怎么能把横幅放在我的所有视角控制器中?
现在,我只在RootViewController上有横幅.
我总共有4个视图控制器.
谢谢.
但我想知道,我怎么能把横幅放在我的所有视角控制器中?
现在,我只在RootViewController上有横幅.
我总共有4个视图控制器.
谢谢.
解决方法
你想要的是一个GADBannerView单例.您可以创建一个包装类来充当adView的单例,如下所示:
@interface GADMasterViewController : UIViewController { GADBannerView *adBanner_; BOOL didCloseWebsiteView_; BOOL isLoaded_; id currentDelegate_; }
并确保GADMasterViewController始终返回一个单例:
+(GADMasterViewController *)singleton { static dispatch_once_t pred; static GADMasterViewController *shared; // Will only be run once,the first time this is called dispatch_once(&pred,^{ shared = [[GADMasterViewController alloc] init]; }); return shared; }
-(void)resetAdView:(UIViewController *)rootViewController { // Always keep track of currentDelegate for notification forwarding currentDelegate_ = rootViewController; // Ad already requested,simply add it into the view if (isLoaded_) { [rootViewController.view addSubview:adBanner_]; } else { adBanner_.delegate = self; adBanner_.rootViewController = rootViewController; adBanner_.adUnitID = kSampleAdUnitID; GADRequest *request = [GADRequest request]; [adBanner_ loadRequest:request]; [rootViewController.view addSubview:adBanner_]; isLoaded_ = YES; } }
然后展示您的广告只需要:
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; shared = [GADMasterViewController singleton]; [shared resetAdView:self]; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。