一:前提条件
1:将KeyMob与应用集成。
2:您可能还需要先了解发送AdRequest的相关信息以及中介的工作原理。

二:横幅广告自定义事件
在以下示例中,您将首先在KeyMob中介内创建一个横幅广告自定义事件。这需要通过KeyMob界面定义一个自定义事件,指向您应用中的特定类,然后实现自定义事件横幅广告以投放视图。

三:定义自定义事件
自定义事件必须在 KeyMob界面中进行定义。您可以在此帮助中心指南中找到为特定广告单元修改中介的说明。

以下是自定义事件示例的部分设置:
Label:AdMobCustomEvent
Class Name:CustomAd
Parameter:a1401234567890

要定义自定义事件,您仅需提供类的名称作为类名称即可。参数应该包含所有必需的信息,以便向广告网络发送您在自定义事件中实现的广告请求。在这种情况下,KeyMob自定义事件仅需要发布商ID。

四:请求横幅广告
定义名为CustomAd的类,它表示在您的自定义事件设置中定义的类名称。它应该实现GADCustomEventBanner。当系统从中介广告瀑布流中选择自定义事件后,KeyMob中介 SDK 会针对您在设置中提供的类名称调用requestBannerAd方法。您可以使用此方法提供的参数向您所需的广告网络发送横幅广告请求。以下示例向 KeyMob发出了请求。

1:CustomAd.h
@import GoogleMobileAds;

@interface CustomAd:NSObject<GADCustomEventBanner,GADBannerViewDelegate> {
    GADBannerView *bannerView_;
}

@end

2:CustomAd.m
#import "CustomAd.h"

@implementation CustomAd

// Will be set by the Mobile Ads SDK.
@synthesize delegate;

- (void)dealloc {
  bannerView_.delegate = nil;
  [bannerView_ release];
  [super dealloc];
}

#pragma mark -
#pragma mark GADCustomEventBanner
- (void)requestBannerAd:(GADAdSize)adSize
parameter:(NSString *)serverParameter
label:(NSString *)serverLabel
request:(GADCustomEventRequest *)customEventRequest {
// Create the bannerView with the appropriate size.
self.bannerView = [[GADBannerView alloc] initWithAdSize:adSize];

// Set the delegate to listen for callbacks.
self.bannerView.delegate = self;

// Set the publisher ID for the banner. This comes from server parameter
// you provide when creating the custom event in mediation.
  self.bannerView.adUnitID = serverParameter;

// Let the bannerView know which UIViewController to restore after returning
// from and ad click. The UIViewController is available from
// GADCustomEventBannerDelegate.
self.bannerView.rootViewController=[self.delegate    viewControllerForPresentingModalView ];

// Create an ad request using custom targeting options from the custom event
// request

GADRequest *request = [GADRequest request];
[request setAdditionalParameters:[customEventRequest additionalParameters]];

[request setBirthday:[customEventRequest userBirthday]];
[request setGender:[customEventRequest userGender]];
[request setTesting:[customEventRequest isTesting]];

if ([customEventRequest userHasLocation]) {
[request setLocationWithLatitude:[customEventRequest userLatitude]
longitude:[customEventRequest userLongitude]
accuracy:[customEventRequest userLocationAccuracyInMeters]];
  }
     [self.bannerView loadRequest:request];
}

自定义事件必须在成功收到广告或无法收到广告时,通过GADCustomEventBanner通知中介 SDK。否则,自定义事件会超时,中介会继续联系下一个广告网络。

五:通知 KeyMob中介
为您的广告网络实施广告监听器并调用GADCustomEventBanner上的相关回调,以将消息发回给中介。以下示例会实施KeyMob的GADBannerViewDelegate接口,以发送这些消息。
#pragma mark -
#pragma mark GADBannerView Callbacks

- (void)adViewDidReceiveAd:(GADBannerView *)adView {
[self.delegate customEventBanner:self didReceiveAd:adView];
}

- (void)adView:(GADBannerView *)view
didFailToReceiveAdWithError:(NSError *)error {
[self.delegate customEventBanner:self didFailAd:error];
}

- (void)adViewWillPresentScreen:(GADBannerView *)adView {
[self.delegate customEventBanner:self clickDidOccurInAd:adView];
[self.delegate customEventBannerWillPresentModal:self];
}

- (void)adViewWillDismissScreen:(GADBannerView *)adView {
[self.delegate customEventBannerWillDismissModal:self];
}

- (void)adViewDidDismissScreen:(GADBannerView *)adView {
[self.delegate customEventBannerDidDismissModal:self];
}

- (void)adViewWillLeaveApplication:(GADBannerView *)adView {
[self.delegate customEventBannerWillLeaveApplication:self];
}

@end

注意:您必须将所有的回调都通知中介。

您的自定义事件至少应调用GADCustomEventBanner中的以下三种回调:
customEventBanner:didReceiveAd:中介可以展示传递给它的广告。无法调用此回调会导致超时,从而使中介继续联系下一个广告网络。

customEventBanner:didFailAd:中介可以继续从中介广告瀑布流中的下一个广告网络中请求广告,而不必等待超时。

customEventBanner:clickDidOccurInAd:让中介记录并报告您的自定义事件收到的点击次数。

五:插页式广告自定义事件
插页式广告自定义事件的实现方法与横幅广告自定义事件的实现方法类似。两者的主要区别是:您创建的插页式广告自定义事件类应该实现GADCustomEventInterstitial接口(而不是GADCustomEventBanner)。

六:请求插页式广告
以下示例介绍了通过自定义事件请求KeyMob 插页式广告的方法:
1:CustomAd.h
@import GoogleMobileAds;

@interface CustomAd:NSObject<GADCustomEventInterstitial,GADInterstitialDelegate> {
    GADInterstitial *interstitial_;
}

@end

2:CustomAd.m
#import "CustomAd.h"

@implementation CustomAd

// Will be set by the Mobile Ads SDK.
@synthesize delegate;

- (void)dealloc {
  interstitial_.delegate = nil;
  [interstitial_ release];
  [super dealloc];
}

#pragma mark -
#pragma mark GADCustomEventInterstitial

- (void)requestInterstitialAdWithParameter:(NSString *)serverParameter
label:(NSString *)serverLabel
request:(GADCustomEventRequest *)customEventRequest {

// Set the publisher ID for the interstitial. The ID comes from the server
// parameter you provide when creating the custom event.
self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:serverParameter];

// Set the delegate to listen for callbacks.
self.interstitial.delegate = self;

// Create an ad request using custom targeting options from the custom event
// request.
GADRequest *request = [GADRequest request];
[request setAdditionalParameters:[customEventRequest additionalParameters]];
[request setBirthday:[customEventRequest userBirthday]];
[request setGender:[customEventRequest userGender]];
[request setTesting:[customEventRequest isTesting]];

if ([customEventRequest userHasLocation]){
[request setLocationWithLatitude:[customEventRequest userLatitude]
longitude:[customEventRequest userLongitude]
accuracy:[customEventRequest userLocationAccuracyInMeters]];
  }
  [self.interstitial loadRequest:request];
}

- (void)presentFromRootViewController:(UIViewController *)rootViewController {
[self.interstitial presentFromRootViewController:rootViewController];
}

插页式广告自定义事件接口要求您实现presentFromRootViewController:方法。当您告知移动广告SDK 展示插页式广告时,中介层会调用此方法。

七:通知 KeyMob中介
与横幅广告自定义事件示例一样,您需要为广告网络实现广告监听器以将消息转发回中介。以下示例介绍了 KeyMob的GADInterstitialDelegate的实现方法。
#pragma mark GADInterstitial Callbacks

- (void)interstitialDidReceiveAd:(GADInterstitial *)view {
  [self.delegate customEventInterstitial:self didReceiveAd:view];
}

- (void) interstitial:(GADInterstitial *)ad
  didFailToReceiveAdWithError:(GADRequestError *)error {
  [self.delegate customEventInterstitial:self didFailAd:error];
}

- (void)interstitialWillPresentScreen:(GADInterstitial *)ad {
  [self.delegate customEventInterstitialWillPresent:self];
}

- (void)interstitialWillDismissScreen:(GADInterstitial *)ad {
  [self.delegate customEventInterstitialWillDismiss:self];
}

- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
  [self.delegate customEventInterstitialDidDismiss:self];
}

- (void)interstitialWillLeaveApplication:(GADInterstitial *)ad {
  [self.delegate customEventInterstitialWillLeaveApplication:self];
}

@end

将消息发回中介层可让其继续中介广告瀑布流。插页式广告没有点击次数,因此不会有插页式广告点击事件传递回中介层。

这里有一些应用能添加广告教程,如android 应用、IOS应用、 flash air应用、 cordova5应用 ,详细教程网站http://www.keymob.com这是一个专业应用广告管理工具——KeyMob支持插页式广告、横幅广告、Banner、视频广告等众多流行广告平台。打开教程你将会学习到更多,希望能帮到忙!

在AdMob中介内创建横幅广告自定义事件相关推荐

  1. web.xml.jsf_JSF 2.2在30秒内创建一个自定义Hello World组件

    web.xml.jsf 让我们直接跳到很酷的东西上,说在JSF 2.0中,通过在Facelet标记库( *taglib.xml )中对其进行配置,使页面作者可以使用自定义组件. 此外,当将组件映射到J ...

  2. JSF 2.2在30秒内创建一个自定义Hello World组件

    让我们直接跳到很酷的东西上,说在JSF 2.0中,通过在Facelet标记库( *taglib.xml )中对其进行配置,使页面作者可以使用自定义组件. 此外,当将组件映射到JAR中时,需要在web. ...

  3. JS基础-事件模型(事件事件流自定义事件事件冒泡/代理)

    文章目录 一.事件与事件流 二.事件模型 1.DOM0级模型 2.IE事件模型 3.DOM2级模型 4.DOM3级事件处理方式 三.事件对象 四.事件绑定与解除 1.事件绑定 1.1对象.on事件名字 ...

  4. 【JS】512- JS 自定义事件如此简单!

    在前端开发世界中,JavaScript 和 HTML 之间往往通过 事件 来实现交互.其中多数为内置事件,本文主要介绍 JS自定义事件概念和实现方式,并结合案例详细分析自定义事件的原理.功能.应用及注 ...

  5. 微信公众帐号开发教程第14篇-自定义菜单的创建及菜单事件响应

    微信5.0发布 2013年8月5日,伴随着微信5.0 iPhone版的发布,公众平台也进行了重要的更新,主要包括: 1)运营主体为组织,可选择成为服务号或者订阅号: 2)服务号可以申请自定义菜单: 3 ...

  6. 微信公众号开发---自定义菜单的创建及菜单事件响应(java)

    微信5.0发布 2013年8月5日,伴随着微信5.0 iPhone版的发布,公众平台也进行了重要的更新,主要包括: 1)运营主体为组织,可选择成为服务号或者订阅号: 2)服务号可以申请自定义菜单: 3 ...

  7. Vue高德地图自定义信息窗内绑定点击事件

    因为信息窗肯定是在生成标记后点击触发的事件,所以在 methods 中直接定义点击生成标记事件,不过多赘述,本文主要解决点击标记弹出的信息窗内的点击事件绑定问题  这是高德官方文档中 自定义窗口数据的 ...

  8. Document.createEvent() 创建自定义事件

    document.createEvent用于创建事件,在DOM Level 2 的事件中就有HTMLEvents,MouseEvents,UIEvents事件类型. 应用举例: // 创建事件 var ...

  9. 【JavaScript】- createEvent() 创建自定义事件

    document.createEvent 用于创建事件,在DOM Level 2 的事件中就有HTMLEvents,MouseEvents,UIEvents 事件类型.DOM Level 3增加很多事 ...

最新文章

  1. jQuery-1.9.1源码分析系列(四) 缓存系统
  2. 1097 Deduplication on a Linked List
  3. 360董事长周鸿祎发表全员信:疫情当前,要做好长期在家办公的准备
  4. php时间处理类,PHP常见的日期处理
  5. 【前端】react and redux教程学习实践,浅显易懂的实践学习方法。
  6. OA中总结:s:select,关于使用modelDriven,项目分层,@Transactional,jspf,各个层上配置注解交给spring管理的方法,简单的OGNL表达式写法
  7. :传递给 left 或 substring 函数的长度参数无效。_Java函数式编码结构-好程序员
  8. hdu 4530(数学)
  9. 使用域超级管理员打开Exchange 2010发现没有权限
  10. 12个git实战建议和技巧
  11. java检查危险品程序_危险品检查java程序
  12. Java -- AWT 画图,图像处理
  13. 【图论】用链式前向星(邻接表)存有向图(图文代码逐句分析)
  14. 【语音识别】基于matlab DWT算法0~9数字语音识别【含Matlab源码 1726期】
  15. 关于手机打开pdf文档乱码的解决办法
  16. snipaste滚动截图方法_windows史上最强截图工具 ,有它就够了
  17. 「Wekan」- 看板工具 @20210403
  18. 欧洲杯:匈牙利vs葡萄牙时间:06-15 23:59 星期二
  19. Cookie和Session的作用,区别和各自的应用范围,cookie、Session工作原理
  20. 卷积神经网络超详细介绍

热门文章

  1. 知识付费系统:内容付费、知识变现、知识经济
  2. 国内VCSEL激光器方案厂商(持续更新)
  3. Python设计代码,检测密码强度
  4. 电子器件系列32:逻辑与门芯片74LS11
  5. 使用python解释器
  6. Oracle开发者性能课第8课(如何更快地进行插入、更新和删除)实验
  7. OpenGL3.0教程 第十六课:阴影贴图
  8. 计算机二级和文管二级的考试区别,计算机文管二级考试复习资料1.doc
  9. centos7 目录扩容 LVM
  10. RCNN、FastRCNN、FasterRCNN、YOLO、SSD网络结构通俗解读(一)