【问题标题】:Why won't admob interstitial ads display?为什么 admob 插页式广告不显示?
【发布时间】:2017-03-16 22:20:40
【问题描述】:

所以我在我的 unity android 项目中添加了来自 admob 的横幅广告和插页式广告。所以我在我的测试设备上对其进行了测试,我的横幅广告显示正常,但我的插页式广告不会显示。

我已经在每 11 场比赛中展示了插页式广告:

public void OnCollisionEnter2D(Collision2D other)
    {

        if (other.gameObject.tag == "Pipe")
        {
            s.GameOver();
            targetVelocity.y = 0;
            targetVelocity.x = 0;
            cube.gameObject.SetActive(false);
            score.gameObject.SetActive(false);
            this.anime2.enabled = true;

        }


        PlayerPrefs.SetInt("Ad Counter", PlayerPrefs.GetInt("Ad Counter") + 1);

        if (PlayerPrefs.GetInt("Ad Counter") > 10)
        {
            if (interstitial.IsLoaded())
            {
                interstitial.Show();
            }

            PlayerPrefs.SetInt("Ad Counter", 0);
        }
    }

这是我的请求代码:

private void RequestInterstitial()

    {
#if UNITY_ANDROID

        string adUnitId ="ca-app -pub-3960055046097211/6145173288";

#elif UNITY_IPHONE

        string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";

#else

        string adUnitId = "unexpected_platform";

#endif

        // Initialize an InterstitialAd.

        InterstitialAd interstitial = new InterstitialAd(adUnitId);

        // Create an empty ad request.

        AdRequest request = new AdRequest.Builder().Build();

        // Load the interstitial with the request.

        interstitial.LoadAd(request);
    }

当然之后我调用了 start() 中的方法。

那么问题出在哪里?我应该把这个脚本放在一个空对象上吗?

【问题讨论】:

  • 在使用之前尝试记录adUnitId ,看看你得到了哪个ID。你是否用真实的 id 替换了 else 块中的 id?
  • 另外,您是否在 logcat 中看到任何与 admob 相关的错误/消息?
  • 你试过调试这段代码吗?你能到达这条线:interstitial.Show() 吗?请求插页式()?还要检查您的 adUnitId 是否正确,因为由于某种原因可能会检测到平台错误
  • 好吧,我已经检查了 adUnitId 两次,没问题?我该如何调试它?logcat?因为我是新开发人员

标签: unity3d admob ads


【解决方案1】:

如上所述添加权限并在更新中调用插页式广告,因为加载需要一段时间。谢谢

enter code here

InterstitialAd interstitial;
bool check;

private void RequestInterstitial()
{

     interstitial = new InterstitialAd(adUnitId);
    AdRequest request = new AdRequest.Builder().Build();
    interstitial.LoadAd(request);

}
void Update()
{
    if (!check) {
        if (interstitial.IsLoaded ()) {
            interstitial.Show ();
            check = true;
        }
    }
}
enter code here

【讨论】:

    【解决方案2】:

    如果您想使用插页式广告,您需要在您的 Manifest 文件中添加一些权限。

    将保存广告的广告活动。整个项目只需要一个并请求使用互联网加载广告的权限(如果您还没有要求它们用于其他内容):

    <manifest ...>
    
      <!-- Include required permissions for Google Mobile Ads to run-->
      <uses-permission android:name="android.permission.INTERNET"/>
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    
      <application>
    
         //...
    
         <!--Include the AdActivity configChanges and theme. -->
         <activity android:name="com.google.android.gms.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
          android:theme="@android:style/Theme.Translucent" />
      </application>
    </manifest>
    

    Source.

    【讨论】:

    • 之前添加的所有内容,但仍然不会显示
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多