2012-02-24 84 views
0

我有一個應用程序嘗試檢索iAd,如果不成功則加載AdMob廣告。它可以在iPhone上完美運行,但在iPad上運行時,會出現持續循環,阻止應用程序加載。不斷self.addSubView無法在iPad上工作

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{ 

@try { 
    NSLog(@"Ad Error, looking for AdMob Ad..."); 

    // Create a view of the standard size at the bottom of the screen. 
    bannerView_ = [[GADBannerView alloc] 
        initWithFrame:CGRectMake(0.0, 
              self.view.frame.size.height - 
              GAD_SIZE_320x50.height, 
              GAD_SIZE_320x50.width, 
              GAD_SIZE_320x50.height)]; 

    // I know the banner size is incorret for iPad but it's only supposed to run 
    // on iPad in compatibility mode and changing doesn't help 

    // Specify the ad's "unit identifier." This is your AdMob Publisher ID. 
    bannerView_.adUnitID = @"XXXXXXX"; 


    // Let the runtime know which UIViewController to restore after taking 
    // the user wherever the ad goes and add it to the view hierarchy. 
    bannerView_.rootViewController = self; 
    [self.view addSubview:bannerView_]; 

    GADRequest *admobRequest = [GADRequest request]; 

    admobRequest.testDevices = [NSArray arrayWithObjects: 
           GAD_SIMULATOR_ID,        
           nil]; 

    // Initiate a generic request to load it with an ad. 
    [bannerView_ loadRequest: admobRequest]; 


    [iAdBanner setHidden: YES]; 
    [bannerView_ setHidden: NO]; 
} 
@catch (NSException *e) { 
    NSLog(@"Exception: %@", e); 
} 
@finally { 
} 
} 

NSLog打印出和應用程序不加載:下面是一些代碼。

012-02-24 21:58:38.991 TrophyConverter Free[2948:15e03] Ad Error, looking for AdMob Ad... 
2012-02-24 21:58:38.992 TrophyConverter Free[2948:15e03] Ad Error, looking for AdMob Ad... 
2012-02-24 21:58:38.994 TrophyConverter Free[2948:15e03] Ad Error, looking for AdMob Ad... 

有沒有其他人經歷過這個?我如何過來呢?我設法使用bool來停止連續日誌打印並加載應用程序,但未顯示廣告。

編輯: 問題完全消失,當我刪除此行

[self.view addSubview:bannerView_]; 

這是沒有幫助的,因爲這是增加了AdMob的視圖的一部分。

我也嘗試將構建目標更改爲通用應用程序而不是iPhone應用程序。這解決了這個問題,但我不希望它是一個通用的應用程序,我沒有爲它創建佈局。

+0

什麼是錯誤? – MyztikJenz 2012-02-25 16:06:58

+0

@MyztikJenz沒有錯誤,didFailToReceiveAdWithError一直被調用[self.view addSubView:bannerView_]。這就像一個永無止境的循環。最終我得到一個EXC_BAD_ACCESS,並且在調試過程中我無法查看self.view,所以我猜這是與此有關的。我使用ARC雖然所以沒有早期版本或任何東西 – Peter 2012-02-25 16:22:12

+0

@MyztikJenz我有一個蘋果的崩潰日誌,如果這可以幫助你。我注意到你爲他們工作:) – Peter 2012-02-25 16:32:22

回答

0

最終我找不到這個問題的解決方法,所以我基本上添加了一個一旦發生故障就被切換的布爾。那麼如果支票已經完成並且還沒有工作,則不會添加任何廣告。