0

我使用 Cordova 1.9.0,尝试为 iOS 实施 Admob 广告并在 self.viewController 处收到错误...: property viewController not found。我尝试了 modalViewController、parentViewController、...但它不能正常工作。如何实施适用于 iOS 的 AdMob?我需要启用/禁用来自 javascript 的广告。指令链接:https ://groups.google.com/forum/?fromgroups#!topic/phonegap/_Lf4o6xiUK0 谢谢。

4

2 回答 2

0

要在 ios phonegap 中集成 admob,请按照以下步骤操作

  1. 在 xcode 中创建您正常的日常 phonegap (1.0.0) 项目

  2. 导入 GoogleAdMobAdsSDK 文件夹和所需的 AdMob 框架(我相信 phonegap 项目中唯一没有的就是 MessageUI.framework)

  3. 在 AppDelegate.h - 然后执行 #import “GADBannerView.h” 并添加 GADBannerView *bannerView_; 到你的@interface

  4. 在 AppDelegate.m 中 – #define MY_BANNER_UNIT_ID @“您的 AdMob 发布商 ID# 这里”现在是棘手的部分。这导致我把头撞在墙上一段时间

    5.) 将您的方法 webViewDidFinishLoad 更改为 this 。. .

    (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)

于 2012-07-02T11:34:53.453 回答
0

试试这个插件点击查看
添加插件

cordova plugin add cordova-admob

然后将下面的代码添加到您的 javascript 文件中,并将 ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB 更改为您的 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);
于 2015-12-29T18:12:54.453 回答