iOS开发-植入广告(iAd, Admob实例)
2014-09-18 09:18
477 查看
应用中植入广告是一种很好的盈利手段。
下面介绍主流的两种方法。iAd, Admob
先mark一个很详细的pdf。 http://pan.baidu.com/share/link?shareid=1656439633&uk=1394536315&fid=406566606116897
2. .h文件加入如下代码
3. .m文件加入如下代码
效果图:
<喎�"http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD48cD48YnIgLz48L3A+PHA+PGJyIC8+PC9wPjxwPjxiciAvPjwvcD48cD48aDE+tv6ho2FkbW9iIDwvaDE+PC9wPjxwPjEu0OjSqrzTyOu12sj9t73OxLz+LNLUvLDI58/CZnJhbWV3b3JrPC9wPjxwPjxpbWcgc3JjPQ=="http://www.2cto.com/uploadfile/Collfiles/20140511/201405110921014.png"
alt="\" />
2.
3. .h文件加入如下代码
3. .m文件加入如下代码
.m文件代码
下面介绍主流的两种方法。iAd, Admob
先mark一个很详细的pdf。 http://pan.baidu.com/share/link?shareid=1656439633&uk=1394536315&fid=406566606116897
一。iAd
1.需要加入iAd.framework2. .h文件加入如下代码
#import #import @interface ViewController : UIViewController
3. .m文件加入如下代码
#import "ViewController.h" @interface ViewController () @property (nonatomic,strong)ADBannerView *adView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.adView = [[ADBannerView alloc]initWithFrame:CGRectMake(0, 64, 320, 50)]; self.adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait]; self.adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait; self.adView.delegate = self; [self.view addSubview:self.adView]; } - (void)bannerViewWillLoadAd:(ADBannerView *)banner{ NSLog(@"bannerViewWillLoadAd"); } - (void)bannerViewDidLoadAd:(ADBannerView *)banner { NSLog(@"bannerViewDidLoadAd"); } - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error { NSLog(@"didFailToReceiveAdWithError"); }
效果图:
<喎�"http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD48cD48YnIgLz48L3A+PHA+PGJyIC8+PC9wPjxwPjxiciAvPjwvcD48cD48aDE+tv6ho2FkbW9iIDwvaDE+PC9wPjxwPjEu0OjSqrzTyOu12sj9t73OxLz+LNLUvLDI58/CZnJhbWV3b3JrPC9wPjxwPjxpbWcgc3JjPQ=="http://www.2cto.com/uploadfile/Collfiles/20140511/201405110921014.png"
alt="\" />
2.
#define ADID @"xxxxxxx" //设置一个自己的全局id
3. .h文件加入如下代码
#import #import "GADBannerView.h" @interface AdmobDefaultViewController : UIViewController { GADBannerView *ADView; }
3. .m文件加入如下代码
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // Create a view of the standard size at the bottom of the screen. ADView = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0,self.view.frame.size.height - GAD_SIZE_320x50.height,GAD_SIZE_320x50.width,GAD_SIZE_320x50.height)]; ADView.adUnitID = ADID;//调用id ADView.rootViewController = self; ADView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:ADView]; [ADView loadRequest:[GADRequest request]]; }
3。ADMOB插屏广告
.h文件代码#import #import "GADInterstitial.h" #import "GADInterstitialDelegate.h" @interface InterAdmobViewController : UIViewController @property(nonatomic, retain) GADInterstitial *interstitial; @end
.m文件代码
- (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [[GADInterstitial alloc] init]; self.interstitial.delegate = self; self.interstitial.adUnitID = ADID; [self.interstitial loadRequest: [self createRequest]]; } - (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. nil nil]; return request; } - (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial { [interstitial presentFromRootViewController:self]; }
相关文章推荐
- iOS开发-植入广告(iAd, Admob实例)
- iOS开发-植入广告(iAd, Admob实例)
- iOS开发-植入广告(iAd, Admob实例)
- iOS开发之iAd苹果广告
- iOS开发用swift添加admob广告,iosswiftadmob广告
- iOS开发笔记[19/50]:集成iAd广告
- iOS开发用swift添加iAd广告
- 【iOS开发】在 App 中加入 AdMob 广告 - 入门介绍与编程技巧
- iOS如何植入admob广告
- iOS开发用swift添加admob广告
- IOS开发广告接入iAD框架_InMobi框架
- iOS如何植入admob广告
- iOS 开发 初级:插入Admob 广告
- IOS开发中NSString类的使用 实例
- iOS:集成iAd广告
- ios开发笔记如何在iphone-and-ipad应用程序添加admob
- Xcode4.3开发第一个IOS应用实例【转】
- Xcode4.3开发第一个IOS应用实例
- joomla1.5开发一个广告随机显示模块实例
- Xcode4.3 开发第一个IOS应用实例