📜  iOS-iAd集成

📅  最后修改于: 2020-12-08 06:24:14             🧑  作者: Mango


iAd用于显示由Apple服务器提供的广告。 iAd帮助我们从iOS应用程序中获得收入。

iAd集成-涉及的步骤

步骤1-创建一个简单的基于视图的应用程序。

步骤2-选择您的项目文件,然后选择目标,然后在选择框架中添加iAd.framework。

步骤3-更新ViewController.h如下-

#import 
#import 

@interface ViewController : UIViewController {
   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

输出

运行应用程序时,将获得以下输出-

iOS教程