如何添加admob广告添加流程到现有的Unity3D ios游戏

IOS版Cocos2d-x2.2使用移动广告聚合平台集成插屏广告教程 - 开源中国社区
当前访客身份:游客 [
当前位置:
发布于 日 15时,
KeyMob移动广告聚合平台支持的广告形式有横幅广告、插屏广告、积分墙广告、视频广告、push广告、全屏广告等众多流行广告形式,目前是国内比较优秀的平台,也是日广告量展示量比较不错的移动广告聚合平台。
代码片段(1)
1.&[代码][其他]代码&&&&
Cocos2d-x 2.2
GoogleAdMobAdsSdkiOS-6.5.1
2.1 导入头文件和.a文件
并在Librabry Search Paths中添加.a文件的路径
2.2 导入所需IOS框架
AdSupport.framework
StoreKit.framework
AudioToolbox.framework
MediaPlayer.framework
MessageUI.framework
SystemConfiguration.framework
2.3 Linking中添加Other Linker Flags
否则会遇到-[GADObjectPrivate
changeState:]: unrecognized selector sent to instance的问题。
首先要导入GADInterstitila.h头文件,实现GADInterstitialDelegate委托,并定义一个GADInterstitila属性。showInterstitial方法供外部调用用来显示广告。
#import &UIKit/UIKit.h&
#import "GADInterstitial.h"
@class RootViewC
@interface AppController : NSObject &UIApplicationDelegate,GADInterstitialDelegate& {
UIWindow *
RootViewController
GADInterstitial
*interstitial_;
@property(nonatomic, retain) GADInterstitial *
- (void)showI
.m文件中主要是delegate函数的实现,interstitial初始化,广告预先请求和广告显示等方法
#pragma mark -#pragma Interstitial Delegate
- (void)interstitial:(GADInterstitial *)interstitial
didFailToReceiveAdWithError:(GADRequestError *)error {
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad
[self preloadRequest];
#pragma mark GADRequest generation
// Create a new GADInterstitial each time.
A GADInterstitial
// will only show one request in its lifetime. The property will release the
// old one and set the new one.
self.interstitial = [[[GADInterstitial alloc] init] autorelease];
self.interstitial.delegate =
// Note: Edit InterstitialExampleAppDelegate.m to update
// INTERSTITIAL_AD_UNIT_ID with your interstitial ad unit id.
self.interstitial.adUnitID = INTERSTITIAL_AD_UNIT_ID;
-(void)preloadRequest
CCLOG("pre load");
[self initInterstitial];
[self.interstitial loadRequest: [self createRequest]];
// Here we're creating a simple GADRequest and whitelisting the application
// for test ads. You should request test ads during development to avoid
// generating invalid impressions and clicks.
- (GADRequest *)createRequest {
GADRequest *request = [GADRequest request];
// Make the request for a test ad. Put in an identifier for the simulator as
// well as any devices you want to receive test ads.
request.testDevices =
[NSArray arrayWithObjects:
// TODO: Add your device/simulator test identifiers here. They are
// printed to the console when the app is launched.
跟android不同的是,interstitial对象每次request时都必须重新初始化。
完整的.m文件:
#import "AppController.h"
#import "EAGLView.h"#import "cocos2d.h"
#import "AppDelegate.h"
#import "RootViewController.h"
#define INTERSTITIAL_AD_UNIT_ID @"YOUR_OWN_ID"
@implementation AppController
@synthesize interstitial = interstitial_;
#pragma mark -
#pragma mark Application lifecycle
// cocos2d application instancestatic AppDelegate s_sharedA
static AppDelegate s_sharedA
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
// Init the EAGLView
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
pixelFormat: kEAGLColorFormatRGB565
depthFormat: GL_DEPTH24_STENCIL8_OES
preserveBackbuffer: NO
sharegroup: nil
multiSampling: NO
numberOfSamples: 0];
// Use RootViewController manage EAGLView
viewController=[[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
viewController.view = __glV
// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] & 6.0)
// warning: addSubView doesn't work on iOS6
[window addSubview: viewController.view];
// use this method on ios6
[window setRootViewController:viewController];
[window makeKeyAndVisible];
[[UIApplication sharedApplication] setStatusBarHidden:true];
//[self initInterstitial];//每次request都要重新初始化
[self preloadRequest];
cocos2d::CCApplication::sharedApplication()-&run();
return YES;
- (void)applicationWillResignActive:(UIApplication *)application {
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
cocos2d::CCDirector::sharedDirector()-&pause();
- (void)applicationDidBecomeActive:(UIApplication *)application {
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
cocos2d::CCDirector::sharedDirector()-&resume();
- (void)applicationDidEnterBackground:(UIApplication *)application {
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
cocos2d::CCApplication::sharedApplication()-&applicationDidEnterBackground();
- (void)applicationWillEnterForeground:(UIApplication *)application {
Called as part of
transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
cocos2d::CCApplication::sharedApplication()-&applicationWillEnterForeground();
- (void)applicationWillTerminate:(UIApplication *)application {
Called when the application is about to terminate.
See also applicationDidEnterBackground:.
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
- (void)dealloc {
interstitial_.delegate =
[interstitial_ release];
[window release];
[super dealloc];
#pragma mark
-#pragma Interstitial Delegate
- (void)interstitial:(GADInterstitial *)interstitial
didFailToReceiveAdWithError:(GADRequestError *)error {
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad
[self preloadRequest];
- (void)showInterstitial{
if (self.interstitial.isReady) {
CCLOG("ready");
[self.interstitial presentFromRootViewController:viewController];
CCLOG("not ready");
[self preloadRequest];
#pragma mark GADRequest generation
-(void)initInterstitial
// Create a new GADInterstitial each time.
A GADInterstitial
//will only show one request in its lifetime. The property will release the
//old one and set the new one.
self.interstitial = [[[GADInterstitial alloc] init] autorelease];
self.interstitial.delegate =
// Note: Edit InterstitialExampleAppDelegate.m to update
// INTERSTITIAL_AD_UNIT_ID with your interstitial ad unit id.
self.interstitial.adUnitID = INTERSTITIAL_AD_UNIT_ID;
-(void)preloadRequest
CCLOG("pre load");
[self initInterstitial];
[self.interstitial loadRequest: [self createRequest]];
// Here we're creating a simple GADRequest and whitelisting the application
// for test ads. You should request test ads during development to avoid
// generating invalid impressions and clicks.
- (GADRequest *)createRequest {
GADRequest *request = [GADRequest request];
// Make the request for a test ad. Put in an identifier for the simulator as
// well as any devices you want to receive test ads.
request.testDevices =
[NSArray arrayWithObjects:
// TODO: Add your device/simulator test identifiers here. They are
// printed to the console when the app is launched.
#elif(CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
[(AppController*)[UIApplication sharedApplication].delegate showInterstitial];
KeyMob移动广告聚合平台支持的广告形式有横幅广告、插屏广告、积分墙广告、视频广告、push广告、全屏广告等众多流行广告形式,目前是国内比较优秀的平台,也是日广告量展示量比较不错的移动广告聚合平台。
开源中国-程序员在线工具:
相关的代码(132)
开源从代码分享开始
大街小巷的其它代码flash air应用添加KeyMob广告管理库中文教程 - 开源中国社区
当前访客身份:游客 [
当前位置:
发布于 日 11时,
Keymob是一个专业的移动应用广告管理工具,支持百度广告,admob广告,广点通,mmedia,inmobi,chartboost,iad,adcolony视频广告等众多流行广告平台。使用Keymob可以顺利通过应用市场审核;通过keymob可以方便的应用交叉推广,设定各个广告平台的比例和优先顺序,还可以方便的完成定向推广,自主销售广告,互换广告和控制广告的内容与价格
代码片段(1)
1.&[代码][其他]代码&&&&
要在手机应用里面展示广告需要在应用里面添加广告管理库,KeyMob广告管理库目前的版本是 下载解压后可以看到flash air工程的目录结构,大部分常规的flash air工程文件和目录,下面资源是KeyMob管理库相关的。
A:README.md KeyMob 英文快速集成文档
B:README_zh.md KeyMob 中文快速集成文档
KeyMob1.0.ane KeyMob 广告管理核心库
1:com_KeyMob_sdks KeyMob 备用平台
2:biduad_plugin KeyMob 百度平台需要的资源
3:gdt_plugin KeyMob 广点通平台需要的资源
注意:上述src下目录和目录下面的文件都不能修改名称
com_KeyMob_sdks 目录下面有个 AdmobAdapter.jar 表示KeyMob使用admob作为无法连接KeyMob时的备用广告平台如果想改用别的平台 可以下载更多的备用平台。
除上面下载的资源外,使用KeyMob官方支持的平台,无需再单独添加各个平台的代码
添加管理库到flash mobile工程项目
添加使用广告管理库需要下面几步骤:
1复制 KeyMob1.0.ane 到自己flash air工程的下,然后添加到编译路径
2复制 com_KeyMob_sdks 到自己flash air工程的src下
3如果要使用百度广告平台,复制 biduad_plugin 到自己flash air工程的src下
4如果要使用广点通平台,复制 gdt_plugin 到自己flash air工程的src下
添加广告相关as3代码
1.首先import KeyMob相关的类
import com.KeyMob.*;
2.初始化KeyMob
初始化KeyMob管理库是调用其他广告功能函数的前提,必须先初始化才能做别的调用,下面是使用 服务的初始化方式
KeymobAD.getInstance().initFromJSON(jsonString);
jsonString 是上面的json配置字符串,包含各个广告平台的配置信息
3.展示广告
下面把显示横幅广告在绝对位置(0,200)示例
KeyMobAd.getInstance().showBannerABS(AdSizes.BANNER,0,200);
参数说明: AdSizes.BANNER 第一个参数广告尺寸,所有默认支持的广告横幅尺寸都在AdSizes类中 "0" 第二个参数是广告的位置x "200" 第二个参数是广告的位置y
4.添加广告权限
编辑xxx-app.XML 给应用添加需要的权限,例如网络请求,下面是大部分广告平台需要的权限
&!-- base permission --&
&uses-permission android:name="android.permission.INTERNET"/&
&uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&
&uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/&
&uses-permission android:name="android.permission.READ_PHONE_STATE"/&
&!-- base permission for location--&
&uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&
&uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&
&!-- base permission
required by chartboost and baidu--&
&uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&
&!-- permission required by mmedia --&
&uses-permission android:name="android.permission.RECORD_AUDIO" /&
&uses-feature android:name="android.hardware.microphone" android:required="false" /&
5.添加广告Activity等配置信息
编辑xxx-app.XML给应用添加广告平台的Activity,未添加平台的activity将无法展示平台广告
&!-- Admob --&
&meta-data android:name="com.google.android.gms.version" android:value="7327000"/&
&activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent"/&
&!-- Amazon Mobile Ads --&
&activity android:name="com.amazon.device.ads.AdActivity" android:configChanges="keyboardHidden|orientation|screenSize"/&
&!-- InMobi --&
&activity android:name="com.inmobi.androidsdk.IMBrowserActivity" android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize"android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:hardwareAccelerated="true" /&
&!-- Millennial Media --&
&activity android:name="com.millennialmedia.android.MMActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar" android:configChanges="keyboardHidden|orientation|keyboard|screenSize" &&/activity&
&!-- KeyMob --&
&activity android:name="com.keymob.sdk.core.KeymobActivity"
android:theme="@android:style/Theme.Dialog" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /&
&!-- baidu --&
&activity android:name="com.baidu.mobads.AppActivity" android:configChanges="keyboard|keyboardHidden|orientation"/&
&!-- adcolony --&
&activity android:name="com.jirbo.adcolony.AdColonyOverlay" android:configChanges="keyboardHidden|orientation|screenSize" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" /&
&activity android:name="com.jirbo.adcolony.AdColonyFullscreen" android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" /&
&activity android:name="com.jirbo.adcolony.AdColonyBrowser" android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" /&
&!-- guang dian tong --&
&service android:name="com.m.DownloadService" android:exported="false"/&
&activity android:name="com.qq.e.ads.ADActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize"/&
广告平台信息配置文件模板
平台参数以json的格式组织,样子如下:
"isTesting":true,//是否是测试模式
"rateModel":1,//广告平台排序规则,0表示priority是权重,各个平台按比例显示广告,1表示priority是顺序,各个平台按顺序展示广告
"platforms":[
{"class":"AdmobAdapter","priority":90,"key1":"ca-app-pub-xxx/xxx","key2":"ca-app-pub-xxx/xxx"},//admob 平台 ,key1 banner ID,key2全屏id
{"class":"AmazonAdapter","priority":20,"key1":"xxx"},//amazon 平台 ,key1 appkey
{"class":"ChartboostAdapter","priority":40,"key1":"xxx","key2":"xxx"},//chartboost 平台 ,key1 appID,key2 signature
{"class":"InmobiAdapter","priority":50,"key1":"xxx"},//inmobi 平台 ,key1 appid
{"class":"IadAdapter","priority":50,"key1":""},//iad 平台 ,android上会被自动忽略
{"class":"KeyMobAdapter","priority":50,"key1":"appid"},// 自售广告,交叉推广需要
{"class":"BaiduAdapter","priority":50,"key1":"appsid","key2":"appsec"},//baidu 平台
{"class":"GDTAdapter","priority":50,"key1":"appid","key2":"banner id","param":"full id"},//广点通 平台,param也可以是json格式{"interstitialID":"全屏广告ID","appWallID":"应用墙ID"}
{"class":"AdcolonyAdapter","priority":50,"key1":"appid","key2":"full id","param":"video id"},//adcolony 平台
{"class":"MMediaAdapter","priority":10,"key1":"xxx","key2":"xxx"}//mmedia 平台 ,key1 banner ID,key2全屏id
各个广告平台Key1,Key2,param表示的意义:
1.Admob 1:key1 横幅广告ID
2:key2 全屏广告ID 3:param 无需设置
2.Inmobi 1:key1 广告属性ID
2:key2 无需设置
3:param 无需设置
3.Chartboost 1:key1 appId
2:key2 appSignature 3:param 无需设置
4.MMedial 1:key1 banner广告位id
2:key2 全屏广告位id 3:param rect广告位id
5.Iad 1:key1
2:key2 无需设置
3:param 无需设置
6.Amazon 1:key1 广告ID
2:key2 无需设置
3:param 无需设置
2:key2 appsec,改版后和appid一样的值
3:param 无需设置
8.KeyMob 1.key1 应用ID
2.key2 无需设置 3.param 无需设置
9.广点通 a.key1 应用ID
b.key2 banner 广告位
c.param 针对IOS应用是全屏广告位,针对android是json格式的字符串,包括全屏和应用墙 {"interstitiID":"全屏广告ID","appWallID":"应用墙ID"}
10.Adcolony
1.key1 应用ID
2.key2 全屏视频广告ID
3.param 奖励型视频广告ID
开源中国-程序员在线工具:
相关的代码(132)
开源从代码分享开始
大街小巷的其它代码【在你的游戏中加入广告,来赚大钱呦! unity 5.3 iap unity iap】-蛮牛译馆-【游戏蛮牛】-虚拟现实,unity3d,unity3d教程下载首选u3d,unity3d官网_unity3d U3D教程官网 ios开发 Android开发 游戏开发平台-游戏蛮牛
在你的游戏中加入广告,来赚大钱呦!
本帖最后由 OVATION 于
16:30 编辑
SHOWING ADS IN YOUR GAME TO MAKE MONEY在你的游戏中加入广告,来赚大钱呦!
原文链接是//ads-monetization-overview/。& && &一款游戏的成功并不只是单纯由它的流行度决定,还取决于赞助商、广告商等人对这款游戏的财务支持。当你正开发一款游戏时,你一定会强烈感受到如何通过游戏赚钱。通常,你一定会关注三种主要方法来实现游戏商业化:
1.& && &付费下载或付费试玩----玩家愿意付费下载你的游戏
2.& && &免费----玩家完全是免费玩游戏的,你只通过广告来挣钱
3.& && &在程序内购买(IAP)----玩家乐意购买游戏中的道具或升级游戏
除了明显的付费下载和IAP(程序内购买)以外,还能使用何种方法赚钱呢?大多数时间是通过展示广告完成的。相比于付费游戏,用智能方式展示广告的免费类游戏通常能挣到更多的钱。而且他们的资源更为丰富----高德纳公司预计截至到2017年,所有游戏都将变成免费下载的。最近的研究报告也告诉我们,游戏的广告收入在2015年达到了历史最高值258亿美元----所以,游戏制作人有大把大把机会过来捞钱。
如果你正打算在免费游戏或IAP游戏中加入广告,重要的是要去评估你游戏的玩家。比如,愿意直接为你游戏付费的玩家占比多少呢?另外,不愿为你游戏花一毛钱的玩家又是多大比例呢?这道问题***是绝大多数用户(根据Swrve的研究报告,这个数字是97.8%)不愿意为你的游戏花钱。理想丰满,现实骨感,只有广告给你机会能通过玩家赚钱,尤其是那些吝啬的玩家。
每一次,在你游戏中播放广告时,你就能够赚钱了----这就是大家对广告收入的基本印象。你或许也了解过“eCPM”这个术语,它全称是Effective CostPer Mille (thousand views)。通常,它描述了广告每一千次展示给游戏制作人时,带来的广告收入。
首先你要做的事情是寻求出色的广告联盟,从而进行合作(譬如Unity Ads)。广告联盟会甄选出将在你游戏中展示的广告,并给你付费----仅仅是在你游戏中生成他们的SDK,并***在你游戏中。在之后的博文中,Unity将给大家介绍用不同方法实现游戏广告收益的最大化。
在整合广告联盟之后,你应该总要密切关注供应比率----时间百分比,它与一个广告联盟成功提供给你玩家一个有需求的广告有关。广告联盟的供应比率越高,你公开所花的钱就越少。因为一个广告总是在得到玩家请求后,才展示给大众。
你还要关注CTR(点击率)。它表示点击你广告的玩家除以所有看你广告的玩家的比例。广告与你玩家用户越相关,就有更多的人愿意点击广告。最终,就能挣到更多的钱。所以,游戏制作人要与广告联盟商细心而又缜密的合作,他们才会给你展示出玩家最喜爱看的广告。
& && &Unity之后的博文将会给大家带来:不同的广告类型,以及如何在你游戏中加入最棒的广告。
& && & OVATION小编之前翻译过相关文章,游戏广告的简单介绍,请看链接:/thread-.html。
unity 5.3unity iap
关注我,关注蛮牛译馆Q群,一起翻译国外技术文章,为蛮牛们带来干货。欢迎大家来捧场哩?(^ω^)?
这个必须顶{:87:}{:87:}{:87:}{:87:}
小小程序员
很好,对我有用,谢谢啦{:104:}
小小程序员
要是能发一些国内或者国外的广告SDK就更好了
独立游戏开发者
ADMOB比较靠谱
独立游戏开发者
独立游戏开发者 发表于
ADMOB比较靠谱
虽然eCPM较低,但比较稳定,结款放心。
AdMob没有unitySDK,需要自己实现,国内的广告平台也都没有unitySDK,
UnityAds是unity自家的广告平台.
谢谢 分享, 学习了,非常好非常好啊
小小程序员
peizhijia 发表于
AdMob没有unitySDK,需要自己实现,国内的广告平台也都没有unitySDK,
UnityAds是unity自家的广告平台.
很厉害,如果大神找到unity广告SDK了,还望给小伙伴们分享一下,谢谢{:94:}
这个可以有,符合中国市场。{:90:}
毕竟肯买游戏的不多????还是靠广告赚吧????
独立游戏开发者
本帖最后由 独立游戏开发者 于
22:44 编辑
peizhijia 发表于
AdMob没有unitySDK,需要自己实现,国内的广告平台也都没有unitySDK,
UnityAds是unity自家的广告平台.
Admob有Unity的SDK. 下载帖子地址: Admob的Unity插件帖子
独立游戏开发者
小小程序员 发表于
很厉害,如果大神找到unity广告SDK了,还望给小伙伴们分享一下,谢谢
Admob有Unity的SDK. 下载帖子地址: Admob的Unity插件帖子
这是个值得好好研究的的问题!
查看完整版本:

参考资料

 

随机推荐