在cocos2d Game中增添AdMob

在cocos2d Game中添加AdMob

1.先在谷歌的AdMob网站上注册一个帐号,
2.添加一个iphone或ipad手机应用广告
3.下载发布者代码,并记住发布者ID
4.下载下来的发布者代码里面有6个.h头文件和一个.a文件.把他们加入你的工程里
5.添加下面4个framework
     (1)AudioToolbox.framework
     (2)MessageUI.framework
     (3)SystemConfiguration.framework
     (4)CoreGraphics.framework
6.在工程里设置你要在那个场景加,许多人都会加到rootViewController里,我是要加到特定的场景里所以用以下做法
  (1)在.h里添加
#import "GADBannerView.h"
  (2)在.m中添加方法
-(void)addAdMob
{


controller = [[RootViewController alloc]init];
CGSize size = [[CCDirector sharedDirector]winSize];
controller.view.frame = CGRectMake(0,0, size.width, size.height);
//创建一个标准大小的屏幕
bannerView_ = [[GADBannerView alloc]
                   initWithFrame:CGRectMake(80,size.height-GAD_SIZE_320x50.height-270,//可以设置你广告的位置
                                            GAD_SIZE_320x50.width,
                                            GAD_SIZE_320x50.height)];

//指定广告的“单位标识符”。这是您的AdMob的发布者
bannerView_.adUnitID = @"发布者ID";

//用户的广告,将它添加到视图
bannerView_.rootViewController = controller;

[controller.view addSubview:bannerView_];
[[[CCDirector sharedDirector]openGLView]addSubview:controller.view];

//启动一个通用请求加载广告。
[bannerView_ loadRequest:[GADRequest request]];
}
- (void)releaseAdMob {
[controller.view removeFromSuperview];
[bannerView_ release];
[controller release];
}
这样运行你的程序就可以在你要显示广告的场景里看到一条广告了.