微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Admob 测试广告奖励广告在构建后不会显示在真实设备上

如何解决Admob 测试广告奖励广告在构建后不会显示在真实设备上

我在使用 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 举报,一经查实,本站将立刻删除。