【发布时间】:2019-05-01 02:04:51
【问题描述】:
我的 iOS 游戏有以下代码,我只是将它集成到一个空场景中
public class AdController : MonoBehaviour
{
void Start()
{
print ("------------------ initializing ads --------------------");
#if UNITY_ANDROID
string appId = "ca-app-pub-xxxxxxxxxxxxxxxxx~xxxxxxxxxxxxxx";
#elif UNITY_IPHONE
string appId = "ca-app-pub-xxxxxxxxxxxxxxxxxx~xxxxxxxxxxxxx";
#else
string appId = "unexpected_platform";
#endif
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize (appId);
RequestInterstitial();
}
private InterstitialAd interstitial;
private void RequestInterstitial()
{
print ("----------- RequestInterstitial -------------");
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxx";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxx";
#else
string adUnitId = "unexpected_platform";
#endif
this.interstitial = new InterstitialAd(adUnitId);
// Called when an ad request has successfully loaded.
this.interstitial.OnAdLoaded += HandleOnAdLoaded;
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().
AddTestDevice("xxxxxxxxxxmydevicexxxxxxxxxxx")
.Build();
// Load the interstitial with the request.
this.interstitial.LoadAd(request);
}
public void HandleOnAdLoaded(object sender, EventArgs args)
{
print("HandleAdLoaded event received");
showInterstitial ();
}
void showInterstitial()
{
if (this.interstitial.IsLoaded ()) {
this.interstitial.Show ();
} else {
print ("ad not ready yet");
}
}
}
当我的广告展示 1 秒后自动消失。这是解释我的问题的视频链接
https://www.dropbox.com/s/kvrjew0cr8ayqzo/LDFA2437.MP4?dl=0
我做错了什么?
【问题讨论】:
-
我不太确定,但可能与测试环境有关。用真实的广告和设备试一试,看看你是否有这个问题。
-
首先我尝试了测试广告,他们有这种行为。然后我放了实时的 admob 单元 ID。我有同样的结果。在视频中,我使用的是实时广告。
-
但是在您的视频中,您仍然会看到测试广告“这是一个插页式测试广告”。也许这条线:
AddTestDevice(). -
我将移除我的测试设备,然后分享结果
-
我移除了我的测试设备并尝试使用实时广告,甚至我看到了......它再次像测试广告一样消失了。
标签: c# unity3d admob interstitial