0
我正在使用admob插件處理Ionic 3項目。我創建了兩個變量(Mybanner和Myinterstital是)存儲AdMob的代碼,我想從外部URL獲得這些變量的內容一樣,如何從一個變量從url到離子變量?
http://example.com/admob.php
,然後把它放在這裏:
id: this.Myabanner,
id: this.Myinterstitial,
因爲我想隨時從網站上更改admob代碼。
import { AdMobFree, AdMobFreeBannerConfig, AdMobFreeInterstitialConfig, AdMobFreeRewardVideoConfig } from '@ionic-native/admob-free';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
Myabanner= "ca-app-pub-3940256099942544/6300978111";
Myinterstitial= "ca-app-pub-3940256099942544/1033173712";
// this tells the tabs component which Pages
// should be each tab's root Page
constructor(public navCtrl: NavController, private adMobFree: AdMobFree) {
this.showInterstitialAd();
this.ionViewDidLoad();
this.showVideoRewardsAd()
}
ionViewDidLoad() {
const bannerConfig: AdMobFreeBannerConfig = {
id: this.Myabanner,
isTesting: false,
autoShow: true
};
this.adMobFree.banner.config(bannerConfig);
this.adMobFree.banner.prepare()
.then(() => {
})
.catch(e => console.log(e));
}
async showInterstitialAd() {
try {
const interstitialConfig: AdMobFreeInterstitialConfig = {
id: this.Myinterstitial,
isTesting: false,
autoShow: true
}
this.adMobFree.interstitial.config(interstitialConfig);
const result = await this.adMobFree.interstitial.prepare();
console.log(result);
}
catch (e) {
console.error(e)
}
}
async showVideoRewardsAd() {
try {
const videoRewardsConfig: AdMobFreeRewardVideoConfig = {
//id: 'ca-app-pub-3940256099942544/5224354917',
isTesting: true,
autoShow: true
}
this.adMobFree.rewardVideo.config(videoRewardsConfig);
const result = await this.adMobFree.rewardVideo.prepare();
console.log(result);
}
catch (e) {
console.error(e);
}
}
}
是啊,這多虧的方式,但我怎麼可以存儲成變量 – Mr2upp