如何配置iAd
by Elton on 六.29, 2010, under iPhone
1. 导入iAd.framework
2.选择要定制iAd的TabViewController.h , 添加代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #import <UIKit/UIKit.h> #import <iAd/ADBannerView.h> @interface TabViewController : UIViewController<ADBannerViewDelegate> { 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 |
3.对应的TabViewController.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #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 |



六月 29th, 2010 on 18:38
写的不错,以后经常过来看看!一起加油!
七月 4th, 2010 on 11:41
博客不错啊,路过!
七月 14th, 2010 on 10:16
nice little blog you got, theme custom? Looks really great
七月 26th, 2010 on 19:48
Would you mind taking a minute of your time to help us out with a quick eval? Compensation is provided to the quickest who can help us. We left the link in the proper field, thankyou
八月 1st, 2010 on 01:54
A very interesting read and a great post alltogether. Would you mind if I posted the same article on my blog (with a reference to your website)?
八月 7th, 2010 on 01:56
Excellent read, I must say. You’ve researched the topic very well :)
八月 7th, 2010 on 12:40
I do agree with all the ideas you have presented in your post. They are very convincing and will definitely work. Thanks for the post.
九月 6th, 2010 on 07:29
I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.
九月 6th, 2010 on 08:31
I recently came across your web site and have been reading along. I thought I would leave my very first comment. Nice blog. I will keep visiting this website very frequently.
十月 16th, 2010 on 14:28
Thanks for your share!