2017-10-29 8 views
1

나는 cocos2d에서 보상 광고 또는 삽입 광고를 게재하려했지만 성공하지 못했습니다. 간질를 들어 내가 보상 광고를 위해 나는 다음과 같은 코드를 사용하고있는 다음 코드AdMob 광고하기 Objective C를 사용하여 Cocos2d에 광고 및 삽입 광고를 보냅니다.

- (void)createAndLoadInterstitial { 
    _interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"ID"]; 
    _interstitial.delegate = self; 
    [_interstitial loadRequest:[GADRequest request]]; 
} 
/// Tells the delegate an ad request succeeded. 
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad { 
    NSLog(@"interstitialDidReceiveAd"); 
    if (_interstitial.isReady) { 
     //[_interstitial presentFromRootViewController:[CCDirector sharedDirector]]; 
     [_interstitial presentFromRootViewController:self]; 
    } else { 
     NSLog(@"Ad wasn't ready"); 
    } 

} 
/// Tells the delegate an ad request failed. 
- (void)interstitial:(GADInterstitial *)addidFailToReceiveAdWithError:(GADRequestError *)error { 
    NSLog(@"interstitial:didFailToReceiveAdWithError: %@", [error localizedDescription]); 
    [self displayBannerAd]; 
} 
/// Tells the delegate that an interstitial will be presented. 
- (void)interstitialWillPresentScreen:(GADInterstitial *)ad { 
    NSLog(@"interstitialWillPresentScreen"); 
} 
/// Tells the delegate the interstitial is to be animated off the screen. 
- (void)interstitialWillDismissScreen:(GADInterstitial *)ad { 
    NSLog(@"interstitialWillDismissScreen"); 
} 
/// Tells the delegate the interstitial had been animated off the screen. 
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad { 
    NSLog(@"interstitialDidDismissScreen"); 
} 
/// Tells the delegate that a user click will open another app 
/// (such as the App Store), backgrounding the current app. 
- (void)interstitialWillLeaveApplication:(GADInterstitial *)ad { 
    NSLog(@"interstitialWillLeaveApplication"); 
} 

을 사용하고

- (void)display_reward_ad{ 
    [GADRewardBasedVideoAd sharedInstance].delegate = self; 
    [[GADRewardBasedVideoAd sharedInstance] loadRequest:[GADRequest request] withAdUnitID:@"ID"]; 
} 
- (void)rewardBasedVideoAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd didRewardUserWithReward:(GADAdReward *)reward { 
    NSString *rewardMessage = [NSString stringWithFormat:@"Reward received with currency %@ , amount %lf", reward.type, [reward.amount doubleValue]]; 
    NSLog(@"%@,",rewardMessage); 
} 
- (void)rewardBasedVideoAdDidReceiveAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd { 
    NSLog(@"Reward based video ad is received."); 
    if ([[GADRewardBasedVideoAd sharedInstance] isReady]) { 
     //[[GADRewardBasedVideoAd sharedInstance] presentFromRootViewController:[CCDirector sharedDirector]]; 

     UIView *myView = [[UIView alloc] init]; 
     [[GADRewardBasedVideoAd sharedInstance] presentFromRootViewController:myView]; 
     [[[CCDirector sharedDirector] openGLView] addSubview:[GADRewardBasedVideoAd sharedInstance]]; 
    } 
} 
- (void)rewardBasedVideoAdDidOpen:(GADRewardBasedVideoAd *)rewardBasedVideoAd { 
    NSLog(@"Opened reward based video ad."); 
} 
- (void)rewardBasedVideoAdDidStartPlaying:(GADRewardBasedVideoAd *)rewardBasedVideoAd { 
    NSLog(@"Reward based video ad started playing."); 
} 
- (void)rewardBasedVideoAdDidClose:(GADRewardBasedVideoAd *)rewardBasedVideoAd { 
    NSLog(@"Reward based video ad is closed."); 
} 
- (void)rewardBasedVideoAdWillLeaveApplication:(GADRewardBasedVideoAd *)rewardBasedVideoAd { 
    NSLog(@"Reward based video ad will leave application."); 
} 
- (void)rewardBasedVideoAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd didFailToLoadWithError:(NSError *)error { 
    NSLog(@"Reward based video ad failed to load."); 
} 

어느 한 내가 앱에 위의 코드를 시도 내가 뭘 잘못 말해 줄 수 그것은 작동하지만 Cocos2d에서는 작동하지 않습니다. 아무런 문제없이 배너 광고를 표시하고 있습니다. 도움이나 코드 스 니펫이 좋을 것입니다. 고급

+0

당신은 어떤 오류가 있습니까? 아니면 그냥 나타나지 않습니다. – trungduc

+0

응용 프로그램이 계속 충돌합니다. 예 >>>> 삽입물 던져 예외 표시 : - [CCDirectorDisplayLink presentViewController : animated : completed :] : 인스턴스로 전송 된 인식 할 수없는 선택기 0x156dd7b0 – FreelanceIPhoneDeveloper

+1

[[GADRewardBasedVideoAd sharedInstance] presentFromRootViewController : myView] 함께 [[GADRewardBasedVideoAd sharedInstance] presentFromRootViewController : [[UIApplication sharedApplication] delegate] 윈도우] rootViewController]] – trungduc

답변

1

희망의 감사 도움말 :

UIViewController* rootViewController = [[UIApplication sharedApplication]delegate] window] rootViewController]]; 
[[GADRewardBasedVideoAd sharedInstance] presentFromRootViewController:rootViewController];