2012-07-20 62 views
5

我有一个phonegap应用程序,并试图实施Admob。如何在Phonegap中实现AdMob

我使用PhoneGap的版本1.4.1,我使用这个网站作为我的参考:http://iphone.keyvisuals.com/iphonedev/implementing-admob-ads-in-a-phonegap-project-for-ios-no-plugins-required/

我的代码如下:

(void)webViewDidFinishLoad:(UIWebView *)theWebView 
{ 

bannerView_ = [[GADBannerView alloc]init]; 
[bannerView_ setDelegate:self]; 
[bannerView_ setFrame:CGRectMake(0, 0, 320, 50)]; 

// Specify the ad's "unit identifier." This is your AdMob Publisher ID. 
bannerView_.adUnitID = MY_BANNER_UNIT_ID; 

// 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.viewController; 
[self.viewController.view addSubview:bannerView_]; 

// Initiate a generic request to load it with an ad. 
[bannerView_ loadRequest:[GADRequest request]]; 

// only valid if AdGap.plist specifies a protocol to handle 
if(self.invokeString) 
{ 
    // this is passed before the deviceready event is fired, so you can access it in js when you receive deviceready 
    NSString* jsString = [NSString stringWithFormat:@"var invokeString = \"%@\";", self.invokeString]; 
    [theWebView stringByEvaluatingJavaScriptFromString:jsString]; 
} 
return [ super webViewDidFinishLoad:theWebView ]; 
} 

一切都很好,但是当我运行该应用程序不显示任何广告。

回答

0

请确保您的“theWebView”对象完成其webload。而bannerView_是你的对象的注册属性。

此外,我希望你只是在“MY_BANNER_UNIT_ID”隐藏你的横幅单元ID。

如果横幅广告单元ID正确,请检查您的admob设置。

最后,请使用像查尔斯或类似的iphone代理来验证电话应该熄灭,因为它应该。

0

Phonegap已升级。它支持新功能。只需在配置中添加此代码即可。

<gap:plugin name="com.admob.plugin" version="1.0.0" source="plugins.cordova.io"/>