APP中难免没有广告,广告也是很重要的系统服务。
添加iAD框架
//
// ViewController.m
// iAd
//
// Created by City--Online on 15/5/15.
// Copyright (c) 2015年 XQB. All rights reserved.
//
#import "ViewController.h"
#import <iAd/iAd.h>
@interface ViewController ()<ADBannerViewDelegate>
@property(nonatomic,strong) ADBannerView *bannerView;
@property(nonatomic,assign) BOOL bannerIsVisible;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//ADBannerView继承UIView,所以它也是UIView
self.bannerView=[[ADBannerView alloc]init];
self.bannerView.frame=CGRectMake(0, 0, self.view.bounds.size.width, 40);
self.bannerView.backgroundColor=[UIColor redColor];
self.bannerView.delegate=self;
[self.view addSubview:self.bannerView];
self.bannerIsVisible=YES;
}
//即将Load
- (void)bannerViewWillLoadAd:(ADBannerView *)banner
{
NSLog(@"WillLoad");
}
//Load完成
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(@"ViewDidLoad");
// if(!self.bannerIsVisible)
// {
// [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
// self.bannerView.frame = CGRectOffset(self.bannerView.frame, 0, -100);
// [UIView commitAnimations];
// self.bannerIsVisible = YES;
// }
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
// if(self.bannerIsVisible)
// {
// [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
// self.bannerView.frame = CGRectOffset(self.bannerView.frame, 0, 100);
// [UIView commitAnimations];
// self.bannerIsVisible = NO;
// }
}
//广告点击效果设置(是否允许弹出广告,或是退出应用程序播放广告)返回YES为允许,willLeave表示广告是否会离开当前应用程序
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
return NO;
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
NSLog(@"finish");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
时间: 2024-10-02 21:10:48