如何配置iAd

December 17, 2023
测试
测试
测试
测试
7 分钟阅读
  1. 导入iAd.framework 2.选择要定制iAd的TabViewController.h , 添加代码
#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

  • Previous 理解iPhone项目的BaseSDK和DeploymentTarget含义
  • Next 如何使用SHA1或者MD5校验文件完整性

继续阅读

更多来自我们博客的帖子

如何安装 BuddyPress
由 测试 December 17, 2023
经过差不多一年的开发,BuddyPress 这个基于 WordPress Mu 的 SNS 插件正式版终于发布了。BuddyPress...
阅读更多
Filter如何工作
由 测试 December 17, 2023
在 web.xml...
阅读更多
如何理解CGAffineTransform
由 测试 December 17, 2023
CGAffineTransform A structure for holding an affine transformation matrix. ...
阅读更多