0

我们正在构建一个 iPhone 应用程序并使用这个 iAd 插件:https ://github.com/shazron/iAdPlugin/blob/master/SAiOSAdPlugin.m 。

由于我们在PhoneGap上,所以我们用HTML5而不是Objective-C构建了应用程序,并且不知道如何调整插件。

现在,当 iAd 缺少库存时,它会显示一个白色矩形 (320x50)。发生这种情况时,我们希望显示一个 320x50 的网页而不是白色矩形,作为后备广告。当 iAd 有库存要再次显示时,我们想隐藏此网页并再次显示 iAd。

有人可以提供一些关于如何做到这一点的提示吗?

谢谢!

4

1 回答 1

0

看看我写的这段代码,基本上做同样的事情。真的请注意,这是我的一个项目的简单复制粘贴,但我认为这个概念得到了理解。问有什么不清楚的!基本情况是我有一个名为 iAd 的横幅bannerView和一个名为noIADImageView. 如果 iAd 无法加载,我会将其隐藏以支持noIADImageView

横幅设置(从例如 viewDidLoad 调用):

- (void) setupTheAdBanners {
    // Adding the killer whales ad-banner if the iAds fail to provide an ad.
    [self setupKillerWhalesBanner];

    [bannerView setHidden:YES];
    [noIADImageView setHidden:NO];

    [bannerView setDelegate:self];

    // and make sure it's positioned onscreen.
    bannerView.frame = CGRectMake(0.0, 0.0, bannerView.frame.size.width, bannerView.frame.size.height);
    noIADImageView.frame = bannerView.frame;

    // bring your bannerView to the front
    [self.view bringSubviewToFront:bannerView];
    [self.view bringSubviewToFront:noIADImageView];
}

- (void) setupKillerWhalesBanner {
    //Adding the banner as a subview
    [self.view addSubview:bannerView];

    // Initializing the UIImageView that will show only if the iAd do not display any ads

    CGRect frameBan = CGRectMake(bannerView.frame.origin.x,bannerView.frame.origin.y-bannerView.frame.size.height,bannerView.frame.size.width,bannerView.frame.size.height);

    noIADImageView = [[UIImageView alloc] initWithFrame:frameBan];
    NSLog(@"%f,%f,%f,%f",bannerView.frame.origin.x,bannerView.frame.origin.y-bannerView.frame.size.height,bannerView.frame.size.width,bannerView.frame.size.height);

    [noIADImageView setImage:[UIImage imageNamed:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? @"KillerWhalesBanner-iPad.png" : @"KillerWhalesBanner-iPhone.png")]];

    // ...as hidden
    [noIADImageView setHidden:NO];

    // Setting up a Tap regognizor for the UIImageView
    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
                                             initWithTarget:self action:@selector(clickEventOnImage:)];
    [tapRecognizer setNumberOfTouchesRequired:1];
    [tapRecognizer setDelegate:self];

    // Enables user interaction to the UIImageView
    noIADImageView.userInteractionEnabled = YES;
    [noIADImageView addGestureRecognizer:tapRecognizer];
}

-(void)clickEventOnImage:(id) sender { // Open the Killer Whales app.
    NSLog(@"Clicked banner");
    [self playClickSound];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/killer-whales/id503511808?mt=8"]];
}

当横幅无法加载时,我将其隐藏以支持noIADImageViewas

-(void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    // Failed to load a banner
    NSLog(@"Error with message: %@",error);

    if(error) { //Some sort of error
        [banner setHidden:YES];
        [noIADImageView setHidden:NO];
    }

}
于 2013-05-28T08:22:06.427 回答