self.addSubView无法在iPad上运行

时间:2012-02-24 22:01:20

标签: ios xcode ipad iad

我有一个尝试检索iAd的应用,如果不成功则会加载AdMob广告。它在iPhone上完美运行,但在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应用程序。这解决了问题,但我不希望它是一个通用的应用程序,我没有为它创建布局。

1 个答案:

答案 0 :(得分:0)

我最终无法找到解决方案,所以我基本上添加了一个bool,一旦失败就切换了。如果检查已完成且尚未完成,则不会添加任何广告。