问题描述
我在使用 admob 激励广告时遇到了问题。当我运行项目时,一切正常,但在构建项目后,测试广告(奖励广告)未显示在真实设备上,而测试插页式广告和 测试横幅广告工作正常。有没有人遇到过类似的问题? 我认为问题出在广告请求中
using System;
using GoogleMobileAds.Api;
using UnityEngine;
using UnityEngine.UI;
using GoogleMobileAds.Common;
public class Rewarded : MonoBehavIoUr
{
RewardedAd rewardAd;
public Button watchAd;
string rewardId;
void Start()
{
RequestRewardedAd();
}
//make button interactable if video ad is ready
void Update()
{
if (rewardAd.IsLoaded())
{
watchAd.interactable = true;
}
}
void RequestRewardedAd()
{
#if UNITY_ANDROID
rewardId = "ca-app-pub-3940256099942544/5224354917";
#elif UNITY_IPHONE
rewardId = "ca-app-pub-3940256099942544/5224354917";
#else
rewardId = null;
#endif
rewardAd = new RewardedAd(rewardId);
//call events
rewardAd.OnAdLoaded += HandleRewardAdLoaded;
rewardAd.OnAdFailedToLoad += HandleRewardAdFailedToLoad;
rewardAd.OnAdopening += HandleRewardAdopening;
rewardAd.OnAdFailedToShow += HandleRewardAdFailedToShow;
rewardAd.OnUserEarnedReward += HandleUserEarnedReward;
rewardAd.OnAdClosed += HandleRewardAdClosed;
//create and ad request
if (PlayerPrefs.HasKey("Consent"))
{
AdRequest request = new AdRequest.Builder().Build();
rewardAd.LoadAd(request); //load & show the banner ad
}
else
{
AdRequest request = new AdRequest.Builder().AddExtra("npa","1").Build();
rewardAd.LoadAd(request); //load & show the banner ad (non-personalised)
}
}
//attach to a button that plays ad if ready
public void ShowRewardedAd()
{
if (rewardAd.IsLoaded())
{
rewardAd.Show();
}
}
//call events
public void HandleRewardAdLoaded(object sender,EventArgs args)
{
//do this when ad loads
}
public void HandleRewardAdFailedToLoad(object sender,AdErrorEventArgs args)
{
//do this when ad fails to loads
Debug.Log("Ad Failed to load" + args.Message);
}
public void HandleRewardAdopening(object sender,EventArgs args)
{
//do this when ad is opening
}
public void HandleRewardAdFailedToShow(object sender,AdErrorEventArgs args)
{
//do this when ad fails to show
}
public void HandleUserEarnedReward(object sender,EventArgs args)
{
//reward the player here
//RevivePlayer();
}
public void HandleRewardAdClosed(object sender,EventArgs args)
{
//do this when ad is closed
RequestRewardedAd();
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)