Admob广告的添加

来源:互联网 发布:ubuntu设置ip不起作用 编辑:程序博客网 时间:2024/04/28 16:04

admon广告添加的步骤和注意事项:

1、首先下载admob的API,主要包括下图中的文件

2、直接加载到程序中

3、添加以下几个依赖库

SystemConfiguration.framwork

MessageUI.framework

AdSupport.framework

storeKit.framework

4、在viewcontroller中添加

-(void)addAdMob{    CGSize size = self.view.frame.size;            myBanner = [[[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait] autorelease];    //指定广告的“单位标识符”。这是您的AdMob的发布者        myBanner.frame = CGRectMake(size.width/2 - myBanner.frame.size.width/2,size.height-myBanner.frame.size.height,                                myBanner.frame.size.width,myBanner.frame.size.height);        myBanner.adUnitID = @"a1515917b09dbda";        myBanner.rootViewController = self;    [self.view addSubview:myBanner];        // Initiate a generic request to load it with an ad.    GADRequest *request = [GADRequest request];    #if TARGET_IPHONE_SIMULATOR    request.testing = YES;#endif        NSLog(@"loadRequest start");    [myBanner loadRequest:request];    NSLog(@"loadRequest end");}

如果是用cocos2d

-(void)addAdMob{    CGSize size = [[CCDirector sharedDirector] winSize];            myBanner = [[[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait] autorelease];    //指定广告的“单位标识符”。这是您的AdMob的发布者        myBanner.frame = CGRectMake(size.width/2 - myBanner.frame.size.width/2,size.height-myBanner.frame.size.height,                                myBanner.frame.size.width,myBanner.frame.size.height);        myBanner.adUnitID = @"a1515917b09dbda";        AppController *appDelegate = (AppController*) [[UIApplication sharedApplication] delegate];    [myBanner setRootViewController:[appDelegate navController]];    [[CCDirector sharedDirector].view addSubview:myBanner];        // Initiate a generic request to load it with an ad.    GADRequest *request = [GADRequest request];    #if TARGET_IPHONE_SIMULATOR    request.testing = YES;#endif        NSLog(@"loadRequest start");    [myBanner loadRequest:request];    NSLog(@"loadRequest end");}
5、在初始化函数中,添加[self addmob]

6、设置编译选项,如图

好了,现在应该可以正常运行了,如果仍有问题,请查看官方说明

https://developers.google.com/mobile-ads-sdk/docs/admob/mediation#ios-linker

原创粉丝点击