如何检测iAd是否使用" if"声明

时间:2014-05-17 08:43:33

标签: ios if-statement iad

我有一个代码可以创建一个按钮,具体取决于用户拥有iphone 4或5以及购买IAP以删除广告的时间。以下是代码:

if ((int)[[UIScreen mainScreen] bounds].size.height == 568)
{
    // This is iPhone 5 screen
    if (intvalue == 1) {
        //No Ads
        self.infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
        self.infoButton.tintColor = [UIColor whiteColor];
        self.infoButton.center = CGPointMake(289, 495);
        [self.view addSubview:self.infoButton];
    }
    else{
        //Yes Ads
        self.infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
        self.infoButton.tintColor = [UIColor whiteColor];
        self.infoButton.center = CGPointMake(289, 451);
        [self.view addSubview:self.infoButton];
    }

} else {
    // This is iPhone 4/4s screen
    if (intvalue == 1|) {
        //No Ads
        self.infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
        self.infoButton.tintColor = [UIColor whiteColor];
        self.infoButton.center = CGPointMake(289, 429);
        [self.view addSubview:self.infoButton];
    }
    else{
        //Yes Ads
        self.infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
        self.infoButton.tintColor = [UIColor whiteColor];
        self.infoButton.center = CGPointMake(289, 400);
        [self.view addSubview:self.infoButton];
    }
} 

但是,如果广告未加载,则会出现一个问题。该按钮仍然位于屏幕的较高位置。如何检测广告是否未加载将按钮放置在广告被删除的位置?

1 个答案:

答案 0 :(得分:1)

您需要在班级中实施ADBannerViewDelegate协议。

https://developer.apple.com/library/ios/documentation/userexperience/Reference/ADBannerViewDelegate_Ref/Reference/Reference.html

加载广告后,Apple会调用bannerViewDidLoadAd。

当广告未加载时,Apple会调用bannerView:didFailToReceiveAdWithError:

因此,对于临时修复,在我的代码中,我总是会绘制按钮,就像广告没有加载一样。然后,当广告加载时(在bannerViewDidLoadAd内),请向下移动按钮并显示广告。