我正在尝试在选项卡式应用程序中跨多个视图控制器创建共享的iADBannerView。我尝试了不同的方法来创建它,包括Apple的iAdSuite,但都没有成功。
目前使用我的代码,但是我收到了错误,例如:
“操作无法完成。广告已从此横幅中卸载”
App Delegate .h
#import <iAd/iAd.h>
@interface AppDelegate : UIResponder <ADBannerViewDelegate>{
BOOL bannerIsVisible;
}
@property BOOL bannerIsVisible;
@property (nonatomic, strong) ADBannerView *adView;
App Delegate .m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
return YES;
}
查看控制器.m
- (void)viewDidLoad
{
...
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
appDelegate.adView.delegate = self;
appDelegate.adView.frame = CGRectOffset(appDelegate.adView.frame, 0, self.view.frame.size.height);
[appDelegate.adView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[self.view addSubview:appDelegate.adView];
appDelegate.bannerIsVisible = NO;
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (!appDelegate.bannerIsVisible){
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
appDelegate.bannerIsVisible = YES;
}
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.bannerIsVisible){
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
appDelegate.bannerIsVisible = NO;
}
}
如果有人实施了共享iAd,请提前感谢帮助!
编辑:按照此video
找到解决方案答案 0 :(得分:0)
这是可能的,你所要做的就是用广告制作一个主UIViewController
,然后使用一个包含Tab的容器视图控制器。请参阅以下链接:
这是一个很棒的库,可以为您完成所有管理。 https://github.com/tomohisa/JTCAdBaseViewController