Hello,
I have been searching all over the interweb for a solution, but cannot find any. So I decided to try my luck here and see if anyone can help me fix my issue.
I am using AdMob in Unity and got all of the Test Ads working perfectly. When I switched to the production appId and adUnitId, the banners and ads no longer load.
I built it to my Android, I also loaded it as a BETA app release on Google Play. I do not understand why I am not getting any ads.
This is my code:
using UnityEngine;
using GooglePlayGames.BasicApi;
using GooglePlayGames;
using GoogleMobileAds.Api;
using System;
public class GoogleServicesHandler : MonoBehaviour
{
public GameController gameController;
public static GoogleServicesHandler instance;
private bool signedIn => Social.localUser.authenticated;
private bool useLocalLeaderboard;
private BannerView bannerView;
private RewardBasedVideoAd rewardBasedVideo;
private string iosLeaderboardId = "TopPlayerScoresiOS";
private void Start()
{
if (!signedIn)
{
//Check if the device can reach the internet via a carrier data network or wifi
if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork ||
Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
{
#if UNITY_ANDROID
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
SignIn();
}
}
string appId = "ca-app-pub-2650981032277620~4922009643";
#elif UNITY_IPHONE
if (!signedIn)
{
//Check if the device can reach the internet via a carrier data network or wifi
if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork ||
Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
{
SignIn();
}
}
string appId = "ca-app-pub-2650981032277620~8515151556";
//Do gamecenter stuff here.
#endif
MobileAds.Initialize(appId);
rewardBasedVideo = RewardBasedVideoAd.Instance;
// Called when the user earns reward for watching entire video.
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
// Called when the ad is closed.
rewardBasedVideo.OnAdClosed += HandleRewardBasedVideoClosed;
}
private void SignIn()
{
Social.localUser.Authenticate(success => { Debug.Log("Login success: " + success); });
}
public void RequestRewardBasedVideo()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-2650981032277620/6349643906";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-2650981032277620/6732787280";
#else
string adUnitId = "unexpected_platform";
#endif
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the rewarded video ad with the request.
rewardBasedVideo.LoadAd(request, adUnitId);
}
public void UserOptToWatchAd()
{
if (rewardBasedVideo.IsLoaded())
{
rewardBasedVideo.Show();
}
}
public void HandleRewardBasedVideoClosed(object sender, EventArgs args)
{
print("Requesting video ad");
RequestRewardBasedVideo();
}
public void HandleRewardBasedVideoRewarded(object sender, Reward e)
{
gameController.score = gameController.score * 2;
gameController.GameOver();
}
public void RequestBanner()
{
print("Requesting Banner Ad");
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-2650981032277620/6912203574";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-2650981032277620/8870374778";
#else
string adUnitId = "unexpected_platform";
#endif
// Create a 320x50 banner at the top of the screen.
bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the banner with the request.
bannerView.LoadAd(request);
}
public void DestroyAd()
{
bannerView.Destroy();
}
public void UnlockAchievement(string id)
{
if (signedIn)
{
Social.ReportProgress(id, 100, (bool success) => { });
}
}
public void ShowAchievementsUI()
{
if (signedIn)
{
Social.ShowAchievementsUI();
}
}
public void SendScoreToLeaderboards(long score)
{
if (signedIn)
{
#if UNITY_ANDROID
Social.ReportScore(score, "CgkI0IuFrcsLEAIQAQ", success => { });
#elif UNITY_IOS
Social.ReportScore(score, iosLeaderboardId, success => { });
#endif
}
}
public void ShowLeaderboardsUI()
{
if (signedIn)
{
Social.ShowLeaderboardUI();
}
}
}
I also forced resolve and it resolves android dependencies successfully.
**What am I missing or doing wrong?**
↧