如何在Phonegap中实现AdMob

5
我有一个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 ];
}

一切都很好,但当我运行应用程序时,没有广告显示。

2个回答

0

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

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

0
请确保您的“theWebView”对象完成其网页加载。并且bannerView_是您对象的已注册属性。
另外,我希望您只是输入“MY_BANNER_UNIT_ID”来隐藏您的横幅单元ID。
如果横幅单元ID正确,请检查您的AdMob设置。
最后,请使用iPhone代理(如Charles或类似工具)验证调用是否按照预期进行。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接