English 中文(简体)
Adding admob to an iPhone app with cocos2d make the game crash...?
原标题:

I m working on a cocos2d game on iPhone. The game work perfectly.
Now I want to add an admob ad in the menu of my game. I can see the ad, but after few seconds (or minutes) of playing, the game crash (with no error message...)
Can you see where the problem is?

Menu.h

@interface Menu : CCColorLayer <AdMobDelegate> {  
    AdMobView *adMobAd;  
    NSTimer *refreshTimer;  
} 

Menu.m

+(id) scene {...}  
-(id) init {...}  
-(void) dealloc {...}

- (void)didReceiveAd:(AdMobView *)adView {  
    adMobAd.frame = CGRectMake(-260, 432, 320, 48);  
    CGAffineTransform makeLandscape = CGAffineTransformMakeRotation(M_PI * 0.5f);  
    makeLandscape = CGAffineTransformTranslate(makeLandscape, -216, -134);  
    adMobAd.transform = makeLandscape;  
    [[[CCDirector sharedDirector] openGLView] addSubview:adMobAd];  
    [refreshTimer invalidate];  
    refreshTimer = [NSTimer scheduledTimerWithTimeInterval:AD_REFRESH_PERIOD target:self selector:@selector(refreshAd:) userInfo:nil repeats:YES];  
}  

- (UIViewController *)currentViewController {
    return nil;
}

- (void)onEnter {
    adMobAd = [AdMobView requestAdWithDelegate:self];
    [adMobAd retain];
    [super onEnter];
}

- (void)onExit {
    [adMobAd removeFromSuperview];
    [adMobAd release];
    [super onExit];
}

- (void)refreshAd:(NSTimer *)timer {
    [adMobAd requestFreshAd];
}

- (NSString *)publisherId {
    return @"zzzzzzzzzzzzzz";
}

- (UIColor *)adBackgroundColor {
    return [UIColor colorWithRed:0.2 green:0.6 blue:1 alpha:1];
}

- (UIColor *)primaryTextColor {
    return [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
}

- (UIColor *)secondaryTextColor {
    return [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
}

- (BOOL)mayAskForLocation {
    return NO;
}

Thanks! :-)

最佳回答

I d suggest you get rid of the NSTimer and use a CCTimer instead (and schedule it using CCScheduler).

You can do it with this code:

    refreshTimer = [CCTimer timerWithTarget:self
                                   selector:@selector(refreshAd:)
                                   interval:AD_REFRESH_PERIOD];
    [[CCScheduler sharedScheduler] scheduleTimer:refreshTimer];
问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签