前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >如何配置iAd

如何配置iAd

作者头像
EltonZheng
发布2021-01-26 11:19:36
4430
发布2021-01-26 11:19:36
举报
  1. 导入iAd.framework 2.选择要定制iAd的TabViewController.h , 添加代码
代码语言:javascript
复制
#import <UIKit/UIKit.h>
#import <iAd/ADBannerView.h>
@interface TabViewController : UIViewController {
    ADBannerView *adView;
    UILabel *adStatus;  
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner;
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave;
- (void)bannerViewActionDidFinish:(ADBannerView *)banner;
- (void)bannerView:(ADBannerView *) didFailToReceiveAdWithError:(NSError *)error;
- (void)adAvailabilityDidChange;
@property (nonatomic, retain) ADBannerView *adView;
@property (nonatomic, retain) UILabel *adStatus;
@end
</pre>

3.对应的TabViewController.m
#import "TabViewController.h"
@implementation TabViewController
@synthesize adStatus;
@synthesize adView;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    
    adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 250, 320, 50)];
    self.adView.delegate = self;
    self.adView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:adView];
    
    adStatus = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 200, 30)];
    [self.view addSubview:adStatus];
    
    NSLog(@"Trying to change the ad status");
}
- (void)adAvailabilityDidChange {
    NSLog(@"[iAd]: Ads are available! Let's display one!");
    
    //    if([ADManager sharedAdManager].canPresentModalAd == YES)
    //        [[ADManager sharedAdManager] presentModalAdFromViewController:self];
}
- (void)cancelBannerViewAction {
    NSLog(@"Banner was cancelled!");
    
    self.adStatus.text = @"[iAd]: Bannes was closed.";
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    NSLog(@"[iAd]: Ad did load.");
    self.adStatus.text = @"[iAd]: Ad did load.";
}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave {
    NSLog(@"[iAd]: An action was started from the banner. Application will quit: %d", willLeave);
    
    self.adStatus.text = @"[iAd]: An action was started from the banner. Application will quit: %d", willLeave;
    
    return YES;
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner {
    NSLog(@"[iAd]: Action finished.");
    
    self.adStatus.text = @"[iAd]: Action finished.";
}
- (void)bannerView:(ADBannerView *) didFailToReceiveAdWithError:(NSError *)error {
    NSLog(@"[iAd]: Faild to load the banner: %@", error);
    
    self.adStatus.text = @"[iAd]: Faild to load the banner: %@", error;
}
- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
- (void)dealloc {
    [super dealloc];
}
@end

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档