【问题标题】:Unity admob ads not working on androidUnity admob 广告无法在 android 上运行
【发布时间】:2018-07-08 10:06:02
【问题描述】:

在测试广告在 iOS 上是否正常运行时,我刚刚启动了名为 Dodge: the Game 的 Android 和 iOS 应用。在两个平台上启动游戏时,android 上没有广告,Admob 仪表板中也没有请求。当有 iOS 时。

这是我用来调用广告的代码:

using UnityEngine;
using UnityEngine.SceneManagement;
using GoogleMobileAds;
using GoogleMobileAds.Api;

public class Menu : MonoBehaviour {

private BannerView bannerView;

private void Awake()
{
    SetupAds();
}

void SetupAds()
{
    if (PlayerPrefs.HasKey("AdFree"))
        return;

    #if UNITY_IPHONE
        string appId = "ca-app-pub-9468963556585973~6866139959";
    #elif UNITY_ANDROID
        string appId = "ca-app-pub-9468963556585973~5324184926";
    #else 
        sting appId = "unexpected_platform";
    #endif

    // Initialize the Google Mobile Ads SDK.
    MobileAds.Initialize(appId);

    this.RequestBanner();

}

private void RequestBanner()
{
    #if UNITY_IPHONE
        string adUnitId = "ca-app-pub-9468963556585973/6704565848";
    #elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-9468963556585973/7268247018";
    #else
        string adUnitId = "unexpected_platform";
    #endif

    // Create a 320x50 banner at the top of the screen.
    bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);

    // Create an empty ad request.
    AdRequest request = new AdRequest.Builder().Build();

    // Load the banner with the request.
    bannerView.LoadAd(request);
}

public void StartGame ()
{
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}

public void DisableAds()
{
    Debug.Log("Ads disabled");
    if (PlayerPrefs.HasKey("AdFree"))
        print("Ads already removed");
    else{
        PlayerPrefs.SetInt("AdFree", 1);
        PlayerPrefs.Save();

        bannerView.Destroy();
    }
}
}

【问题讨论】:

  • 你在什么设备上测试过?
  • 在多个 Android 设备上,广告无法正常工作。从 Galaxy s8/9 到旧款手机。在 iPhone 和 iPad 上,广告可以正常工作。

标签: c# android unity3d admob ads


【解决方案1】:

只需要重新导入 Google AdMob sdk。仅此而已。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-05
    • 1970-01-01
    • 2019-09-14
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多