2017-10-29 6 views
1

Ich habe versucht, in cocos2d Prämienanzeigen oder Interstitial-Anzeigen anzuzeigen, aber keinen Erfolg. Bei Interstitial ich den folgenden CodeAnzeigen von AdMob-Reward-Anzeigen und Interstitial-Anzeigen in Cocos2d unter Verwendung von Objective C

- (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"); 
} 

für Belohnung Anzeigen verwende ich den folgenden Code verwende

- (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."); 
} 

Kann jemand mir sagen, was ich falsch mache ich den obigen Code in apps versucht haben, und es funktioniert, funktioniert aber nicht in Cocos2d Ich zeige Banner-Anzeigen ohne Probleme. jede Hilfe oder Code-Snippet wäre großartig. Vielen Dank im fortgeschrittenen

+0

Haben Sie einen Fehler? Oder es erscheint einfach nicht. – trungduc

+0

App stürzt ab Ja, das ist der Fehler >>>> Präsentieren der Interstitial warf Ausnahme: - [CCDirectorDisplayLink presentViewController: animiert: Abschluss:]: unerkannter Selektor an Instanz 0x156dd7b0 gesendet – FreelanceIPhoneDeveloper

+1

Versuchen ersetzen '[[GADRewardBasedVideoAd sharedInstance] presentFromRootViewController: myView] 'mit' [[GADRewardBasedVideoAd sharedInstance] presentFromRootViewController: [[UIApplication sharedApplication] Delegat] Fenster] rootViewController]] ' – trungduc

Antwort

1

Hope this Hilfe :)

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