npm i --save nativescript-audience-network
- 版本:1.0.3
- GitHub: https://github.com/Gvkundalwal/nativescript-audience-network
- NPM: https://npmjs.net.cn/package/nativescript-audience-network
- 下载次数
- 昨天: 0
- 上周: 0
- 上个月: 5
nativeScript-audience-network
安装
在命令提示符下进入您的应用程序根目录并执行
tns plugin add nativescript-audience-network
iOS 目前不支持
Android
横幅广告
以下是支持的功能
createBanner
类型脚本
import * as AudienceNetwork from 'nativescript-audience-network';
import { isIOS } from "tns-core-modules/platform";
export class HomeComponent implements OnInit {
ngOnInit(): void {
// Init audienceNetwork SDK here.
AudienceNetwork.initAds();
}
testing = true;
createBanner() {
let option: CreateBannerOptions = {
// global test banner id
androidBannerId: "<Your audience network banner id>",
margins: {
bottom: 10,
// top:10
},
testing: true,
size: AD_SIZE.STANDARD_BANNER,
};
AudienceNetwork.createBanner(option).then(
() => (this.message = "Banner created"),
(error) => (this.message = "Error creating banner: " + error)
);
}
}
插屏广告
要显示全屏广告,您可以使用此功能。请注意,插屏广告需要在显示之前加载,有两种方法可以实现这一点
preloadInterstitial
在加载视图时使用此功能,以便在您真正想要显示广告的时候(通过调用 showInterstitial
)准备就绪。
preloadInterstitial(){
let option: CreateInterstitialOptions = {
"androidInterstitialId": "<Your audience network Interstitial id>",
"testing": true,
"onAdClosed": this.onInterstitialClosed.bind(this),
"onAdClicked": this.onInterstitialClicked.bind(this)
}
AudienceNetwork.preloadInterstitial(option).then(
()=> {
console.log(
"interstitial preloaded - you can now call 'showInterstitial' whenever you're ready to do so"
);
}, (error)=> {
console.log("preloadInterstitial error: " + error);
}
);
}
onInterstitialClosed() {
console.log("ad closed");
};
onInterstitialClicked() {
console.log("ad clicked");
}
showInterstitial
在 preloadInterstitial
成功解析后的任何时刻,您都可以调用 showInterstitial
。
请注意,当您再次想要使用 showInterstitial
时,也必须再次使用 preloadInterstitial
,因为这些广告不能重复使用。
showInterstitial(){
AudienceNetwork.showInterstitial()
}
preloadRewardedVideoAd
在加载视图时使用此功能,以便在您真正想要显示广告的时候(通过调用 showRewardedVideoAd
)准备就绪。
preloadRewardedVideoAd(){
let option = {
androidAdPlacementId: "<Your audience network RewardedVideo id>"
}
AudienceNetwork.preloadRewardedVideoAd(option).then(()=> {
console.log(
"RewardedVideoAd preloaded - you can now call 'showRewardedVideoAd' whenever you're ready to do so"
);
},(error)=> {
console.log("preloadRewardedVideoAd error: " + error);
}
);
}
showRewardedVideoAd
在 preloadRewardedVideoAd
成功解析后的任何时刻,您都可以调用 showRewardedVideoAd
。
请注意,当您再次想要使用 showRewardedVideoAd
时,也必须再次使用 preloadRewardedVideoAd
,因为这些广告不能重复使用。
onRewarded
可能是您唯一需要关心的回调函数。
showRewardedVideoAd(){
let option: ShowRewardedOptions = {
"onRewardedVideoAdClosed":this.onRewardedVideoAdClosed.bind(this),
"onRewardedVideoAdOpened":this.onRewardedVideoAdOpened.bind(this),
"onRewardedVideoCompleted":this.onRewardedVideoCompleted.bind(this),
}
AudienceNetwork.showRewardedVideoAd(option)
}
onRewardedVideoAdClosed(){
console.log("onRewardedVideoAdClosed")
}
onRewardedVideoAdOpened(){
console.log("reward clicked")
}
onRewardedVideoCompleted(){
console.log("reward complete")
}