1

Я хочу вызвать интерстициальный просмотр каждые 3 щелчка. Я понял много вопросов типа, но только для родного андроида. Большое спасибо за внимание.Как вызвать admob interstitial каждые 3 щелчка в ионной диаграмме?

Мой 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> 
 

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

 

 
    <script src="lib/ng-cordova.min.js"></script> 
 
    <script src="cordova.js"></script> 
 

 

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

 

 
<script src="js/app.js"></script> 
 
    <script src="js/controllers.js"></script> 
 
    <script src="js/routes.js"></script> 
 
    <script src="js/directives.js"></script> 
 
    <script src="js/services.js"></script> 
 

 
    </head> 
 
    <body ng-app="passLite" animation="slide-left-right-ios7"> 
 

 

 
    <div> 
 
    <div> 
 
    <ion-nav-bar class="bar-assertive"> 
 

 

 
     <ion-nav-back-button class="button-clear"><i class="ion-android-arrow-back"></i> </ion-nav-back-button> 
 
    </ion-nav-bar> 
 
    <ion-nav-view></ion-nav-view> 
 
    </div> 
 

 
</div> 
 
    </body> 
 
</html>

Мой ШАБЛОН

<ion-view title="new" id="page2"> 
 
    <ion-content padding="true" class="has-header"> 
 

 

 
      <!--Config Button--> 
 
     <button class=" animated bounceIn" ng-click="btnClicked('click')"> 
 
     <i class="icon ion-android-refresh"></i> 
 
     </button>   
 

 
     </ion-content> 
 
</ion-view>

Мой CONTROLLER, считавшихся ошибка

angular.module('app.controllers', []) 
 
.controller('new', ['$rootScope', '$scope', '$timeout', '$stateParams', 
 
function ($rootScope, $scope, $timeout, $stateParams) { 
 

 
$scope.counter = 1; 
 
$scope.btnClicked = function(btn){ 
 
     if (btn == 'click'){ 
 

 

 
      //on every 3th clicks show the Interstitial ad one second after the result appears 
 
      if ($scope.counter++ == 3){ 
 
       setTimeout(function(){ 
 
        if (AdMob){ 
 
         AdMob.showInterstitial(); 
 
        } 
 

 
        $scope.counter = 1; 
 
       }, 1000); 
 
      } 
 
     } 
 

 
    }; 
 

 

 
}])

ответ

2

Вы посмотрите на примеры здесь можно: https://github.com/appfeel/admob-google-cordova/wiki/showInterstitialAd и здесь: https://github.com/appfeel/admob-google-cordova/wiki/Angular.js,-Ionic-apps

В основном:

angular.module('myApp', ['admobModule']) 

    .config(['admobSvcProvider', function (admobSvcProvider) { 
    var adPublisherIds = { 
     ios : { 
     banner : "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB", 
     interstitial : "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII" 
     }, 
     android : { 
     banner : "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB", 
     interstitial : "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII" 
     } 
    }; 
    var admobid = (/(android)/i.test(navigator.userAgent)) ? adPublisherIds.android : adPublisherIds.ios; 

    admobSvcProvider.setOptions({ 
     publisherId:   admobid.banner, 
     interstitialAdId:  admobid.interstitial, 
     autoShowInterstitial: false 
    }); 
    }]) 

    .run(['$rootScope', 'admobSvc', function ($rootScope, admobSvc) { 
    $rootScope.isInterstitialAvailable = false; 
    admobSvc.requestInterstitialAd(); 

    // Handle events: 
    $rootScope.$on(admobSvc.events.onAdLoaded, function onAdLoaded(evt, e) { 
     if (e.adType === admob.AD_TYPE.INTERSTITIAL) { 
     $rootScope.isInterstitialAvailable = true; 
     } 
    }); 

    $rootScope.$on(admobSvc.events.onAdClosed, function onAdClosed(evt, e) { 
     if (e.adType === admob.AD_TYPE.INTERSTITIAL) { 
     $rootScope.isInterstitialAvailable = false; 

     // Request next interstitial: there may be some delay 
     // between the moment it is requested and the moment it is available 
     admobSvc.requestInterstitialAd(); 
     } 
    }); 
    }]); 

Тогда в контроллере:

angular.module('app.controllers', []) 
    .controller('new', ['$rootScope', '$scope', '$timeout', '$stateParams', 'admobSvc', function ($rootScope, $scope, $timeout, $stateParams, admobSvc) { 

    $scope.counter = 0; 
    $scope.btnClicked = function(btn) { 
     if (btn == 'click') { 
     $scope.counter += 1; 
     if ($scope.counter >= 3) { 
      $timeout(function() { 
      if ($rootScope.isInterstitialAvailable) { 
       admobSvc.showInterstitial(); 
      } 
      $scope.counter = 0; 
      }, 1); 
     } 
     } 
    }; 
    }]);