简介
IAD由苹果服务器用于显示广告,并帮助我们从应用程序中获得收入。
涉及的步骤
1. 创建一个简单的应用程序。
2. 选择项目文件,然后选择目标,然后选择框架加 iAd.framework。
3. 更新 ViewController.h 如下
#import <UIKit/UIKit.h> #import <iAd/iAd.h> @interface ViewController : UIViewController<ADBannerViewDelegate> { ADBannerView *bannerView; } @end
4. 更新 ViewController.m 如下
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; bannerView = [[ADBannerView alloc]initWithFrame: CGRectMake(0, 0, 320, 50)]; // Optional to set background color to clear color [bannerView setBackgroundColor:[UIColor clearColor]]; [self.view addSubview: bannerView]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - AdViewDelegates -(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{ NSLog(@"Error loading"); } -(void)bannerViewDidLoadAd:(ADBannerView *)banner{ NSLog(@"Ad loaded"); } -(void)bannerViewWillLoadAd:(ADBannerView *)banner{ NSLog(@"Ad will load"); } -(void)bannerViewActionDidFinish:(ADBannerView *)banner{ NSLog(@"Ad did finish"); } @end
输出
现在,当我们运行程序时,我们会得到下面的输出。