0
我正在使用最新的Xcode(4.4.1)併爲iOS 5.1開發。我正在使用Apple提供的底部標籤欄界面。其中一個選項卡使用UIWebView,它利用全屏幕空間。當我嘗試添加由AdMob提供的標準橫幅廣告時,它根本不添加橫幅廣告。我跟着:https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals。代碼如下連接iOS中的AdMob與UIWebView
About.h
#import <UIKit/UIKit.h>
#import "GADBannerView.h"
@interface About : UIViewController <UIWebViewDelegate> {
IBOutlet UIWebView *webView;
// Declare one as an instance variable
GADBannerView *bannerView_;
}
@property (nonatomic, retain) UIWebView *webView;
@end
About.m
#import "About.h"
#import "GADBannerView.h"
#import "GADRequest.h"
#import "constants.h"
@implementation About
@synthesize webView;
//@synthesize bannerView = bannerView_;
+ (void)initialize {
// Set user agent (the only problem is that we can't modify the User-Agent later in the program)
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:UserAgent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
}
- (void)viewDidLoad {
[super viewDidLoad];
NSString *fullURL = ([IsBeta isEqualToString: @"true"]) ? @"http://beta.wouldyouratherapp.com/questions/index/0/1" : @"http://wouldyouratherapp.com/questions/index/0/1";
NSURL *url = [NSURL URLWithString:fullURL]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webView loadRequest:requestObj];
// Create a view of the standard size at the bottom of the screen.
// Available AdSize constants are explained in GADAdSize.h.
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = MyAdUnitID;
// 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;
[self.view addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
@end
是的,我已經加入所有的框架已經和MyAdUnitID已定義的常量文件,所以一切都應該正在工作,但我想我錯過了一些東西。任何幫助?
感謝你的幫助,但是,我已經想通了,它WASN因爲我設置了自己的自定義UserAgent,因此無法加載。我現在需要看看這個問題... – 2012-08-14 23:46:22