Admob无法使用我的离子应用程序

时间:2016-08-13 00:05:32

标签: angularjs ionic-framework admob

我想在我的应用程序中使用Admob,但它无效。它甚至不显示任何java脚本错误。如果我做错了,请告诉我。

这是我的app.js文件

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
var app=angular.module('starter', ['ionic','ngCordova'])

app.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
});
app.controller('AdmobController', function($scope, $ionicPlatform, $cordovaAdMob, $window) {
  $ionicPlatform.ready(function() {

    var adMobId = {
        admob_banner_key: 'ca-app-pub-6468004966999181/9554827955',
        //admob_interstitial_key: ''
    };

    var adMobPosition = {
        BOTTOM_CENTER: 8
    };  

    $scope.showBannerAd = function() {

        try {

            console.log('Show Banner Ad');          

            $cordovaAdMob.createBannerView({
                adId: adMobId.admob_banner_key,
                position: adMobPosition.BOTTOM_CENTER,
                isTesting: true,
                autoShow: true
            });

        } catch (e) {
            alert(e);
        }       
    }
   /*
    $scope.showInterstitialAd = function() {

        try {

            console.log('Show Interstitial Ad');            

            $cordovaAdMob.createInterstitialView({
                adId: adMobId.admob_interstitial_key,
                isTesting: true,
                autoShow: true
            });

        } catch (e) {
            alert(e);
        }       
    }   
  */
  });   
});

这是我的index.html页面:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="js/ng-cordova.min.js"></script>
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
  </head>
  <body ng-app="starter">

    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">Add Mob Example</h1>
      </ion-header-bar>
      <ion-content ng-controller="AdmobController">
      </ion-content>
    </ion-pane>
  </body>
</html>

1 个答案:

答案 0 :(得分:0)

您在控制器范围内创建了一个函数showBannerAd,但从未调用它。在

result

创建showBannerAd函数后,调用:

$ionicPlatform.ready(function() {

});

希望这有帮助。