cocoscreator 之iOS 对接google的广告
Posted zhangyulin311
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cocoscreator 之iOS 对接google的广告相关的知识,希望对你有一定的参考价值。
构建出Xcode代码,按照google官方文档导入google ads的SDK
Js中创建1个点击按钮,
ShowInitAdsinitAds()
jsb.reflection.callStaticMethod("RootViewController", "ShowInitAdsinitAds");
在RootViewController.h中添加类方法
+(void)ShowInitAdsinitAds;
在RootViewController.m中去实现
+(void)ShowInitAdsinitAds
[[NSNotificationCenter defaultCenter] postNotificationName:@"interstitialAds" object:nil];
- (void)viewDidLoad
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showInterstitialAds) name:@"interstitialAds" object:nil];
#pragma mark -- 插页 广告
- (void)showInterstitialAds
self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/4411468910"];
GADRequest *request = [GADRequest request];
[self.interstitial loadRequest:request];
self.interstitial.delegate = self;
/// Tells the delegate an ad request succeeded.
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
NSLog(@"interstitialDidReceiveAd===========");
[self.interstitial presentFromRootViewController:self];
/// Tells the delegate an ad request failed.
- (void)interstitial:(GADInterstitial *)ad
didFailToReceiveAdWithError:(GADRequestError *)error
NSLog(@"interstitial:didFailToReceiveAdWithError===========: %@", [error localizedDescription]);
/// 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===========");
以上是关于cocoscreator 之iOS 对接google的广告的主要内容,如果未能解决你的问题,请参考以下文章