日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

iOS开发-植入广告(iAd, Admob实例)

發布時間:2023/12/15 综合教程 25 生活家
生活随笔 收集整理的這篇文章主要介紹了 iOS开发-植入广告(iAd, Admob实例) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

應用中植入廣告是一種非常好的盈利手段。

以下介紹主流的兩種方法。iAd, Admob

先mark一個非常具體的pdf。 http://pan.baidu.com/share/link?shareid=1656439633&uk=1394536315&fid=406566606116897

一。iAd

1.須要增加iAd.framework

2. .h文件增加例如以下代碼

#import <UIKit/UIKit.h>  
#import <iAd/iAd.h>  
@interface ViewController : UIViewController<ADBannerViewDelegate> 

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");  
}  

效果圖:

<img src="http://img.blog.csdn.net/20140510200330156?

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGl0d2h5bHo=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

二。admob

1.須要增加第三方文件,以及例如以下framework

2.

#define ADID @"xxxxxxx"  
//設置一個自己的全局id

3. .h文件增加例如以下代碼

#import <UIKit/UIKit.h>  
#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 <UIKit/UIKit.h>  
#import "GADInterstitial.h"  
#import "GADInterstitialDelegate.h"  
  
@interface InterAdmobViewController : UIViewController<GADInterstitialDelegate>  
  
@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实例)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。