1

我遇到了一个问题,即 Admob 横幅显示,但是,当您点击它时,它要么使应用程序崩溃,要么什么都不做。

它使用admob中介,与iAd分开,如果显示iAd,可以点击它没有问题...

- (void) onEnter {

    if (![MKStoreManager featureAPurchased])
    {

        controller = [[RootViewController alloc]init];
        bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
        bannerView_.adUnitID = MY_BANNER_UNIT_ID;
        CGRect screenRect = [[UIScreen mainScreen] bounds];
        CGFloat screenWidth = screenRect.size.width;
        CGFloat screenHeight = screenRect.size.height;
        CGFloat screenXPos = (screenWidth /2);
        CGFloat screenYPos = screenHeight - 25;
        [bannerView_ setCenter:CGPointMake(screenXPos, screenYPos)];
        bannerView_.rootViewController = controller;
        bannerView_.adUnitID = MY_BANNER_UNIT_ID;
        bannerView_.rootViewController = controller;
        [[[CCDirector sharedDirector]view] addSubview: bannerView_];
        [bannerView_ loadRequest:[GADRequest request]];


    }else{

        bannerView_.hidden = YES;
    }

错误是如果我尝试点击横幅没有任何反应,并且在控制台中我看到以下错误;

Attempt to present <GADBrowserController: 0x1d576ca0> on <RootViewController: 0x1e8ed3f0> whose view is not in the window hierarchy!

将不胜感激任何帮助

4

1 回答 1

0

不要将横幅视图添加到 CCDirector 的 EAGLView,将其添加到应用程序的 RootViewController

做类似的事情:

 AppDelegate * delegate =[[UiApplication sharedApplication]delegate];
 [delegate.viewController addSubview: bannerView_];
 [delegate bringSubViewToFront:bannerView_]

这样做你根本不需要“控制器”

因此,您基本上是将广告添加到与 EAGLView 相同的级别上。因此,当您展示广告(点击它时)时,您只需将其显示在 glView 上

编辑:

 - (void) onEnter {
   if (![MKStoreManager featureAPurchased])
   {
    bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
    bannerView_.adUnitID = MY_BANNER_UNIT_ID;
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHeight = screenRect.size.height;
    CGFloat screenXPos = (screenWidth /2);
    CGFloat screenYPos = screenHeight - 25;
    [bannerView_ setCenter:CGPointMake(screenXPos, screenYPos)];
    AppDelegate * delegate =[[UiApplication sharedApplication]delegate];
    [delegate.rootViewController addSubview: bannerView_];
    [delegate bringSubViewToFront:bannerView_]
    [bannerView_ loadRequest:[GADRequest request]];
}else{
    bannerView_.hidden = YES;
}
}
}
于 2013-04-12T20:00:38.087 回答