我使用Cordova 1.9.0,尝试为iOS实施Admob广告,并在self.viewController ...中找到错误:找不到属性viewController。 我试过modalViewController,parentViewController,...但它无法正常工作。 如何实现适用于iOS的AdMob? 我需要启用/禁用javascript广告。 指示链接:https://groups.google.com/forum/?fromgroups#!topic/phonegap/_Lf4o6xiUK0 感谢。
答案 0 :(得分:0)
要在ios phonegap中集成admob,请按照以下步骤操作
在xcode中创建正常的日常phonegap(1.0.0)项目
导入GoogleAdMobAdsSDK文件夹和所需的AdMob框架(我相信在phonegap项目中唯一没有的是MessageUI.framework)
在AppDelegate.h中 - 然后实现#import“GADBannerView.h”&添加GADBannerView * bannerView_;到你的@interface
在AppDelegate.m中 - #define MY_BANNER_UNIT_ID @“您的AdMob发布商ID#Here” 现在是棘手的部分。这让我把头撞在了墙上
5.)将您的方法webViewDidFinishLoad更改为此。 。
(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 ];
}
已经完成了
如果您仍然发现任何查询,请仔细查看本指南 APPLYING ADMOB TO PHONEGAP(IOS)
答案 1 :(得分:0)
尝试使用此插件Click to view
添加插件
cordova plugin add cordova-admob
然后将以下代码添加到您的javascript文件中,并将ca-app-pub-XXXXXXXXXXXXXXXXX / BBBBBBBBB更改为您的ID。
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
// Set AdMobAds options:
admob.setOptions({
publisherId: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB", // Required
interstitialAdId: "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII", // Optional
});
// Start showing banners (automatic when autoShowBanner is set to true)
admob.createBannerView();
// Request interstitial (will present automatically when autoShowInterstitial is set to true)
admob.requestInterstitialAd();
}
document.addEventListener("deviceready", onDeviceReady, false);