接著在.h檔設定如下
#import <UIKit/UIKit.h>
#import "GADBannerView.h"
@interface QuoteContentViewController : UIViewController<GADBannerViewDelegate>
{
GADBannerView *bannerView_;
}
.m檔的初始設定,adUnitID更換成自己的廣告id即可
// Create a view of the standard size at the bottom of the screen.
float tabBarHeight = [[[super tabBarController] tabBar] frame].size.height;
float tempHeight = 480.0f - GAD_SIZE_320x50.height - tabBarHeight - 15.0f;
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
tempHeight,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID. a14f05024e9e617
bannerView_.adUnitID = @"a14f6a9cd715868";
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
bannerView_.delegate = self;
[self.view addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
最後如果廣告要求成功的話,會在這個函式收到
- (void)adViewDidReceiveAd:(GADBannerView *)view
{
}
沒有留言:
張貼留言