如何在 Ionic 中实现 Admob? [英] How to implement Admob into Ionic?

查看:33
本文介绍了如何在 Ionic 中实现 Admob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照这篇文章的说明进行操作:AdMob 不在 ionic/angular 应用中加载广告

I followed the instructions of this post: AdMob not loading ads in ionic/angular app

当我通过ionic build ios && ionic emulate ios"运行应用程序时,我没有看到任何广告,也没有黑条.

When I run the app via "ionic build ios && ionic emulate ios" I get no ads, no black bar nothing.

我错过了什么?

谢谢

推荐答案

您可以按照 https://github.com/appfeel/admob-google-cordova/wiki/Angular.js,-Ionic-apps:

  • 照常安装插件(见此处):

  • Install the plugin as usual (see here):

ionic plugin add cordova-admob

  • 在你的index.html中包含以下脚本(就可以了,不需要复制任何文件:插件在准备应用程序时负责复制脚本):

  • Include the following script in your index.html (just it, no need to copy any file: the plugin is in charge to copy the script when the app is prepared):

    <script src="lib/angular-admob/angular-admob.js"></script>
    

  • 从您的 Ionic 应用调用 AdMob.

  • Call AdMob from your Ionic app.

    这是一个简单的例子:

    var app = angular.module('myApp', ['admobModule']);
    
    app.config(['admobSvcProvider', function (admobSvcProvider) {
      // Optionally you can configure the options here:
      admobSvcProvider.setOptions({
        publisherId:          "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",  // Required
        interstitialAdId:     "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII",  // Optional
      });
    }]);
    
    
    app.run(['admobSvc', function (admobSvc) {
      // Also you could configure the options here (or in any controller):
      // admobSvcProvider.setOptions({ ... });
    
      admobSvc.createBannerView();
      // You could also call admobSvc.createBannerView(options);
    
    
      // Handle events:
      $rootScope.$on(admobSvc.events.onAdOpened, function onAdOpened(evt, e) {
        console.log('adOpened: type of ad:' + e.adType);
      });
    }]);
    

    这篇关于如何在 Ionic 中实现 Admob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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