How to display Admob on UIWebView Application?

末鹿安然 提交于 2019-12-12 04:59:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!