2013-04-12 77 views
1

我遇到Admob旗幟顯示的問題,但是,當您點擊它時,它會崩潰應用程序,或者什麼也不做。Admob&Cocos2d - 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! 

希望得到任何援助

回答

0

不旗幟視圖添加到CCDirector的EAGLView,將其添加到應用程序的RootViewController的

做這樣的事情:

​​

這樣做,你不」 t需要'控制器'

所以你基本立法院將在同一水平EAGLView is..so廣告時你目前的廣告(當它拍了拍)你只是顯示它在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; 
} 
} 
} 
+0

嗨Skytz,我會把該代碼放在哪裏?我需要在其他地方聲明任何變量嗎? – user1695971

+0

其他人可以幫忙嗎? – user1695971

+0

@ user1695971只是複製和粘貼我編寫的函數,而不是你編寫的函數 – skytz