共享iAD横幅,但仅限于某些视图

时间:2014-07-18 04:36:42

标签: ios objective-c iad

我已经在appDelegate和某些视图(adbanner委托)中正确实现了共享iAd横幅,但它正确显示。在appdelegate未能检索到Banner时因为没有当前委托并且没有当前的didFailToRecieveAdWithError方法时,我没有显示横幅(因此他们不是adbanner委托)的视图中的控制台显示错误,表示有效地没有方法收到错误。我是否需要将appDelegate也设置为AdBannerDelegate并将这些方法放入其中?

在appDelegate中:

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
_UIiAD = [[ADBannerView alloc]init];
return YES;
}

在ViewController中,我想要一个横幅:

- (CrystalAppDelegate *)appDelegate
{
     return (CrystalAppDelegate *)[[UIApplication sharedApplication]delegate];
}

- (void)viewWillAppear:(BOOL)animated
{

    _UIiAD = [[self appDelegate] UIiAD];
    _UIiAD.delegate = self;

    [_UIiAD setFrame:CGRectMake(0, 518, 320, 50)];
    [self.view addSubview:_UIiAD];
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    NSLog(@"Banner did Load");
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [_UIiAD setAlpha:1];
    [UIView commitAnimations];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"Banner did not Load");
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [_UIiAD setAlpha:0];
    [UIView commitAnimations];
}

-(void)viewWillDisappear:(BOOL)animated
{
    _UIiAD.delegate = nil;
    _UIiAD = nil;
    [_UIiAD removeFromSuperview];
}

问题是当我在一个没有横幅的视图中我没有这些方法时所以当appDelegate没有检索到iAdBanner时,没有方法可以解除错误。

0 个答案:

没有答案