问题
I have previously tried displaying Admobs ads on TabbarView based application. But when I try to implement the same on a UIWebView based application things don't seem to work right.
I tried to add the code inside -(void)viewDidLoad
but the application crashed.
The methods i'm using inside my application include:
(void) viewDidAppear:(BOOL)animated
(void) viewDidDisappear:(BOOL)animated
(void) loading
Where should I implement it to view in my application?
Any help would be appreciated.
回答1:
You can add admob's banner view to window at the end of application:didFinishLaunchingWithOptions: method, after initialising viewController from XIB.
GADBannerView *bannerView;
bannerView = [[[GADBannerView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)] autorelease];
bannerView.adUnitID = @"YOUR_ADMOB_ID";
bannerView.rootViewController = self.viewController;
[self.window addSubview:bannerView];
[bannerView loadRequest:[GADRequest request]];
This way, admob banner will always be on top of the screen.
来源:https://stackoverflow.com/questions/11948475/how-to-display-admob-on-uiwebview-application