为什么我的Admob横幅没有显示?使用故事板

时间:2013-08-26 08:15:37

标签: storyboard admob

有人可以帮助我纠正我在这段代码中的错误,我自己找不到,我认为一切似乎都很好,但没有广告显示。谢谢!

#import "ViewController.h"
#import "GADBannerView.h"
#import "GADRequest.h"

@implementation ViewController

@synthesize adBanner = adBanner_;

- (UIView *)view {
return (UIView *)self.view;
}

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    // Initialization code
}
return self;
}

#pragma mark init/dealloc

// Implement viewDidLoad to do additional setup after loading the view,
// typically from a nib.
- (void)viewDidLoad {


// Initialize the banner at the bottom of the screen.
CGPoint origin = CGPointMake(0.0,
                             self.view.frame.size.height -
                             CGSizeFromGADAdSize(kGADAdSizeBanner).height);

// Use predefined GADAdSize constants to define the GADBannerView.
self.adBanner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
                                                origin:origin];

// Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID
// before compiling.
self.adBanner.adUnitID = @"a15217a5a9b32c4";
self.adBanner.delegate = self;
[self.adBanner setRootViewController:self];
[self.view addSubview:self.adBanner];
self.adBanner.center =
CGPointMake(self.window.center.x, self.adBanner.center.y);
[self.adBanner loadRequest:[self createRequest]];
}

- (void)dealloc {
adBanner_.delegate = nil;

}

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}

#pragma mark GADRequest generation

// Here we're creating a simple GADRequest and whitelisting the application
// for test ads. You should request test ads during development to avoid
// generating invalid impressions and clicks.
- (GADRequest *)createRequest {
GADRequest *request = [GADRequest request];

// Make the request for a test ad. Put in an identifier for the simulator as
// well as any devices you want to receive test ads.
request.testDevices = [NSArray arrayWithObjects:
                       @"3A8012A2-66B8-52F0-8426-2D4CD8D51444",
                       nil];

return request;
}

#pragma mark GADBannerViewDelegate impl

// We've received an ad successfully.
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(@"Received ad successfully");
}

- (void)adView:(GADBannerView *)view
didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]);
}

@end

我正在使用故事板,我一直在网上寻找解决方案,但我似乎没有找到任何有用的东西。

0 个答案:

没有答案