2014-05-17 26 views
0

我有一個代碼可以創建一個按鈕,具體取決於用戶何時使用iphone 4或5以及何時購買了IAP來刪除廣告。下面是它的代碼:如何檢測iAd是否使用「if」語句加載

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]; 
    } 
} 

但是,當我的廣告沒有加載時會出現一個問題。該按鈕在屏幕上的位置應該更高。如何檢測廣告是否沒有加載將按鈕放在廣告被刪除的位置?

+0

看看它的委託方法:'bannerViewDidLoadAd:'? – Larme

回答

1

你需要在你的類中實現ADBannerViewDelegate協議。

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

當一個廣告被加載後,蘋果將調用bannerViewDidLoadAd。

當未加載廣告,蘋果將調用bannerView:didFailToReceiveAdWithError:

所以對於一個臨時的解決辦法,在你的代碼,我總是畫按鈕如果廣告沒有加載。然後,當廣告加載(在bannerViewDidLoadAd內)時,向下移動按鈕並顯示廣告。