gpt4 book ai didi

ios - 使用 Objective C 在 Cocos2d 中展示 AdMob Reward 广告和插屏广告

转载 作者:行者123 更新时间:2023-11-29 11:40:21 26 4
gpt4 key购买 nike

我一直在尝试在 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 中不起作用。我可以毫无问题地展示横幅广告。

最佳答案

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

关于ios - 使用 Objective C 在 Cocos2d 中展示 AdMob Reward 广告和插屏广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46997542/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com