iAd用于显示由Apple服务器提供的广告, iAd帮助无涯教程从iOS应用程序中获得收入。
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)]; //可选择将背景颜色设置为清除颜色 [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
运行应用程序时,将获得以下输出-
参考链接
https://www.learnfk.com/ios/ios-iad-integration.html
标签:iAd,void,OC,无涯,bannerView,ADBannerView,ViewController,banner From: https://blog.51cto.com/u_14033984/7706385