在这段代码中,我在我的 Xcode 项目中添加了 Google AdmobSDK 并尝试显示广告。但我不太确定这段代码是否真的有效!
AdmobiPhoneViewController.m
#import "AdmobiPhoneViewController.h"
#define AdMob_ID @"a151120ca07fb81"
@implementation AdmobiPhoneViewController
- (void)dealloc
{
AdMob.delegate = nil;
[AdMob release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
如果没有超级视图,则释放视图。[super didReceiveMemoryWarning];
释放所有未使用的缓存数据、图像等。} #pragma mark – 视图生命周期 //实现 viewDidLoad 以在加载视图后进行额外设置,通常从 nib 加载。
- (void)viewDidLoad
{
[super viewDidLoad];
AdMob = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0, self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
AdMob.adUnitID = AdMob_ID;
AdMob.rootViewController = self;
[self.view addSubview:AdMob];
GADRequest *r = [[GADRequest alloc] init];
r.testing = YES;
[AdMob loadRequest:r];
}
- (void)viewDidUnload
{
[super viewDidUnload];
//Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
//Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end