如何从MainViewController使用科尔多瓦切换AdMob的观点 [英] How to toggle admob view from MainViewController using Cordova

查看:150
本文介绍了如何从MainViewController使用科尔多瓦切换AdMob的观点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的iPhone应用程序来实现的AdMob,但在创建该视图应根据我的JavaScript的病情进行切换。所以,我需要切换使用科尔多瓦插件这一观点。是否有切换使用的PhoneGap的AdMob的观点的任何可能性?

I have implemented admob in my iPhone app, but the view which was created should be toggled based on my javascript's condition. So, i need to toggle that view using cordova plugins. Is there any possibility of toggling the admob view using phonegap?

推荐答案

我要假设通过拨动你的意思是你要隐藏的视图。你也可能意味着你要申请一个新的广告,但无论我认为逻辑将是相同的。

I'm going to assume that by toggle you mean you want to hide the view. You could also mean you want to request a new ad but regardless I think the logic would be the same.

如果您已经设置了您的AdMob code作为一个插件,你可以写一些JS调用成(你也许可以做到这一点,即使你没有)。因此,JavaScript的方法可能如下:

If you've set up your AdMob code as a plugin, you can write some js that calls into that (you might be able to do this even if you haven't). So the javascript method might look like:

AdMob.prototype.hideAd =
    function(options, successCallback, failureCallback) {
  var defaults = {
    'isHidden': false
  };

  for (var key in defaults) {
    if (typeof options[key] !== 'undefined') {
      defaults[key] = options[key];
    }
  }

  cordova.exec(
      successCallback,
      failureCallback,
      'AdMobPlugin',
      'hideAd',
      new Array(defaults)
  );
};

然后在您的本地code处理该AdMob的观点,你可以做这样的事情:

Then in your native code that handles the AdMob view, you can do something like this:

- (void)hidAd:(NSMutableArray *)arguments
         withDict:(NSMutableDictionary *)options {
  CDVPluginResult *pluginResult;
  NSString *callbackId = [arguments pop];

  if (!self.bannerView) {
    // Try to prevent requestAd from being called without createBannerView first
    // being called.
    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
                                     messageAsString:@"AdMobPlugin:"
                                                     @"No ad view exists"];
    [self writeJavascript:[pluginResult toErrorCallbackString:callbackId]];
    return;
  }
  BOOL isHidden = (BOOL)[[options objectForKey:@"isHidden"] boolValue];
  self.bannerView.hidden  = isHidden;

  pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
  [self writeJavascript:[pluginResult toSuccessCallbackString:callbackId]];
}

这篇关于如何从MainViewController使用科尔多瓦切换AdMob的观点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆