希望在两个插页式广告之间至少留出2分钟的时间

时间:2019-04-16 13:45:55

标签: javascript angular typescript ionic-framework cordova-admob

  

我正在使用带有Cordova-plugin-admob-free的ionic 4,并制作了列表项应用

     

任何项目的第一次点击都会显示一个国际广告,而2分钟后   当我单击任何项​​目时,另一个国际广告将会展示

home.page.ts

import { Component, OnInit } from '@angular/core';
import { RecipiService } from '../services/recipi.service';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {

  items: any;
  constructor(private recipiservice:RecipiService){
  }

  ngOnInit(){
    this.recipiservice.getData();
    this.recipiservice.BannerAd();
  }

   showInterstitial(){
    this.recipiservice.InterstitialAd();
   }
}

recipi.service.ts

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';
import {
  AdMobFree,
  AdMobFreeBannerConfig,
  AdMobFreeInterstitialConfig,
} from '@ionic-native/admob-free/ngx'
import { Platform } from '@ionic/angular'
@Injectable({
  providedIn: 'root'
})
export class RecipiService {
  items: any;
  url = '/assets/resource.json';

  //Interstitial Ad's Configarations
  interstitialConfig: AdMobFreeInterstitialConfig = {
    //add your config
    //for the sake of this example we will just use the test config
    isTesting:true,
    autoShow:false,
    //id: "ca-app-pub-7062962198011740/5161598741"
 };

   constructor(
    private http:HttpClient,
    private admobFree:AdMobFree,
    public platform:Platform
    ) {
      platform.ready().then(() => {
        //Load ad configuration 
        this.admobFree.interstitial.config(this.interstitialConfig);
        //Prepare Ad to show
        this.admobFree.interstitial.prepare()
        .then(() => {
          //alert(1);
        }).catch(e => alert(e));
      });

    //Handle interstitial's close event to Prepare Ad again
    this.admobFree.on('admob.interstitial.events.CLOSE').subscribe(() => {
      this.admobFree.interstitial.prepare();

    });
    }

 BannerAd(){
  let bannerConfig: AdMobFreeBannerConfig = {
    isTesting: true, //Remove in production
    autoShow:true,
    //id: "ca-app-pub-7062962198011740/6309253752"
  };
  this.admobFree.banner.config(bannerConfig);
  this.admobFree.banner.prepare().then(() => {
    //secess
  })//.catch(e => alert(e));
}

InterstitialAd(){
  //Chack if Ad is loaded 

  this.admobFree.interstitial.isReady().then(()=> {
    //will show prepared  Ad
    this.admobFree.interstitial.show().then(()=>{

    })
    //.catch(e => alert("show" + e))
  })
  //.catch(e => alert("isReady" + e))
}

  // get singel data  
  getData(){
    let data: Observable<any> = this.http.get(this.url);
    data.subscribe(results =>{
      // console.log(this.jsons);
        this.items = results;
    })
}

// get full data 
 getDetails(id) {
  let data: Observable<any> = this.http.get(this.url);
   return data
     .pipe(map((items) => {
      return items.find((item) => 
       (item.id == id));

       })
     );
 }
}
我正在使用离子4。而且我正在制作列表项应用。 我正在使用离子4。而且我正在制作列表项应用。 我正在使用离子4。而且我正在制作列表项应用。 我正在使用离子4。而且我正在制作列表项应用。

1 个答案:

答案 0 :(得分:0)

使用间隔每x分钟调用一次Web服务。

//Interval is use to refresh/timeout page, 10000 = 10s
setInterval(data => {
console.log(“test”);
}, 10000);

您可能会使用RxJs的间隔方法。这将为您提供更多的响应选项,而不仅仅是标准的JS间隔调用。

https://www.learnrxjs.io/operators/creation/interval.html