白鹭egret接入facebook广告
问题一:打包后,找不到FBInstant对象
按照文档,在index.html中插入script后,打包上传后找不到FBInstant,查看network后发现压根没有下载fbinstant.7.0.js
<script src="https://www.facebook.com/assets.php/en_US/fbinstant.7.0.js"></script>
解决:需要在template/web/index.html中的header标签中引入
<header>
<script src="https://www.facebook.com/assets.php/en_US/fbinstant.7.0.js"></script>
</header>
问题二:第一次播放奖励视频后,第二次无法播放
预加载视频后,会实例化一个ad instance,在播放完后该实例会被销毁,因此需要再次初始化一次
public preloadedRewardedVideo: FBInstant.AdInstance = null;
public initFBAd() {
let self = this;
FBInstant.getInterstitialAdAsync(
"Placement Id" // Your Ad Placement Id
)
.then(function (interstitial) {
// Load the Ad asynchronously
self.preloadedRewardedVideo = interstitial;
return self.preloadedRewardedVideo.loadAsync();
})
.catch(function (err) {
console.error("Interstitial failed to preload: " + err.message);
});
}
public playFBAd(){
let videoObj = this.preloadedRewardedVideo;
let self = this;
if (videoObj != null) {
videoObj
.showAsync()
.then(function () {
// Perform post-ad success operation
console.log("Rewarded video watched successfully");
self.initFBAd();
})
.catch(function (e) {
console.error(e.message);
});
}
}