当前位置:首页 > 开发 > 移动开发 > 正文

ios下应用程序检测admob广告请求返回和点击事件

发表于: 2012-10-31   作者:bsr1983   来源:转载   浏览次数:
摘要:       因应用需求,需要做一个检测用户点击admob的功能,google上搜索了一圈,没有找到想要的答案,最终只能自己动手,查阅了admob的ios SDK中的几个头文件后,找到了相关的方法,具体如下:       应用中使用的是admob的广告条,即GADBannerView,如要检测GAD
      因应用需求,需要做一个检测用户点击admob的功能,google上搜索了一圈,没有找到想要的答案,最终只能自己动手,查阅了admob的ios SDK中的几个头文件后,找到了相关的方法,具体如下:
      应用中使用的是admob的广告条,即GADBannerView,如要检测GADBannerView相关的事件,如接收广告完成,用户点击广告,用户切回应用等事件,需要实现GADBannerViewDelegate,主要包括的方法如下:
// Sent when an ad request loaded an ad.  This is a good opportunity to add this
// view to the hierarchy if it has not yet been added.  If the ad was received
// as a part of the server-side auto refreshing, you can examine the
// hasAutoRefreshed property of the view.
- (void)adViewDidReceiveAd:(GADBannerView *)view;

// Sent when an ad request failed.  Normally this is because no network
// connection was available or no ads were available (i.e. no fill).  If the
// error was received as a part of the server-side auto refreshing, you can
// examine the hasAutoRefreshed property of the view.
- (void)adView:(GADBannerView *)view
    didFailToReceiveAdWithError:(GADRequestError *)error;

#pragma mark Click-Time Lifecycle Notifications

// Sent just before presenting the user a full screen view, such as a browser,
// in response to clicking on an ad.  Use this opportunity to stop animations,
// time sensitive interactions, etc.
//
// Normally the user looks at the ad, dismisses it, and control returns to your
// application by calling adViewDidDismissScreen:.  However if the user hits the
// Home button or clicks on an App Store link your application will end.  On iOS
// 4.0+ the next method called will be applicationWillResignActive: of your
// UIViewController (UIApplicationWillResignActiveNotification).  Immediately
// after that adViewWillLeaveApplication: is called.
- (void)adViewWillPresentScreen:(GADBannerView *)adView;

// Sent just before dismissing a full screen view.
- (void)adViewWillDismissScreen:(GADBannerView *)adView;

// Sent just after dismissing a full screen view.  Use this opportunity to
// restart anything you may have stopped as part of adViewWillPresentScreen:.
- (void)adViewDidDismissScreen:(GADBannerView *)adView;

// Sent just before the application will background or terminate because the
// user clicked on an ad that will launch another application (such as the App
// Store).  The normal UIApplicationDelegate methods, like
// applicationDidEnterBackground:, will be called immediately before this.
- (void)adViewWillLeaveApplication:(GADBannerView *)adView;

参阅其中的注释可知,常用的方法为:

//客户端接收到广告后调用
- (void)adViewDidReceiveAd:(GADBannerView *)view
{
}
//用户点击广告后调用
- (void)adViewWillPresentScreen:(GADBannerView *)adView
{
    NSLog(@"用户点击");
   
}
//用户点击广告后切换回游戏时
- (void)adViewDidDismissScreen:(GADBannerView *)adView

如果当前存在多个广告栏,可通过检测adView参数的值获取当前产生事件的广告栏对象,实现对应功能。
具体做法是,编写一个类,实现GADBannerViewDelegate,然后在需要检测事件的GADBannerView上设置对应的代理,代码为:
adView.delegate=自定义的实现了GADBannerViewDelegate协议的类对象;

-------------------------------------分割线--------------------------
2012年11月2日 补充
google的admob SDK在不同版本的ios下,点击广告条,所产生的事件是不同的,在ios6.0的ipad中,用户点击广告后调用
- (void)adViewWillPresentScreen:(GADBannerView *)adView
用户切回游戏中时,调用
- (void)adViewDidDismissScreen:(GADBannerView *)adView
但在ios5的iphone中,用户点击广告后调用的却是:
- (void)adViewWillLeaveApplication:(GADBannerView *)adView
用户切回游戏时无事件

ios下应用程序检测admob广告请求返回和点击事件

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
不多说,看步骤。 下载admob广告sdk. 把SDK中的如下文件,除了那个文件夹,全部拖到工程里。 导入文
转自: https://developers.google.com/mobile-ads-sdk/docs/ios/fundamentals?hl=zh-cn 转载仅为防
转自: https://developers.google.com/mobile-ads-sdk/docs/ios/fundamentals?hl=zh-cn 转载仅为防
转自: https://developers.google.com/mobile-ads-sdk/docs/ios/fundamentals?hl=zh-cn 转载仅为防
转自: https://developers.google.com/mobile-ads-sdk/docs/ios/fundamentals?hl=zh-cn 转载仅为防
对于开发面向全球用户的免费软件,插入Google的Admob广告当然还有Apple 的iAd是开发者实现盈利的最
错误1、 2014-12-04 20:07:54.956 AdMobTest[948:33259] +[NSDecimalNumber gad_negativeOne]: unre
http://my.oschina.net/noahxiao/blog/61987?from=rss 长话短说,我喜欢比较直接的方式,好让我们开
在应用中插入广告,很普遍,但是要想在使用Titanium开发的应用中导入广告,去很少。主要是Titanium自
前言:对产品的研究,并不仅仅是看产品是如何设计的,更多的时候是要看产品是如何适可而止的。在研
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号