2017-10-29 42 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

appがクラッシュするはい、エラーです>>>>インタースティシャルのスロー例外を表示する: - [CCDirectorDisplayLink presentViewController:animated:completion:]:インスタンスに送信された認識できないセレクタ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]; 
関連する問題