I’m using latest version of Unity Ads (1.3) with Unity 5 and I can’t get ads working if app was started offline. Advertisement.Initialize() is getting called, but I always get ShowResult.Failed.
Initialize() is called during game startup and at the start of several scenes to be sure UnityAds is initialized when user wants to watch an ad.
I have tested on iOS and Android and the problem is with both platforms.
It seems like if Initialize() is called once during offline, it never works after that. I am using this code and it works fine if started online.
static public void TryShowAd(System.Action<ShowResult> callback)
{
if (Advertisement.isInitialized && Advertisement.IsReady())
{
Advertisement.Show(null, new ShowOptions
{
resultCallback = callback
});
}
else
{
if (Advertisement.isSupported)
{
// this block is executed and text below is printed to log
Debug.Log("UnityAds initialize");
Advertisement.Initialize(GetGameId());
}
else
{
Debug.Log("Platform not supported");
}
callback(ShowResult.Failed);
}
}
Also, it would be great to get notified via callback when UnityAds is initialized.
I got it working by checking internet connection before trying to initialize UnityAds. Basically Advertisement.Initialize() is not called ever if internet connection is not proven to be active. I’m doing this by comparing content of website with hardcoded string to eliminate WiFi networks with custom login sites and such.
This works but there is some overhead because you have to wait for the internet check before even starting to init UnityAds.
Got it, and I agree with you that it should wait for internet connection to become available. Will see how we can get this implemented in a future version of the SDK.
Hi, prior to 5.2 I was implementing a ping check before initialisation and it worked great. However now Unity Ads is integrated initialisation seems to have been taken out of our hands, therefore this method is no longer feasible? Or have i missed something?
Edit: Advertisement.Initialize now has the description “You should only call this method if you have disabled Unity Ads in Connect Window”, which I guess means the Unity Services Window. So basically you cannot control initialisation from integrated Ads and will have to use the plugin. Fair enough.
I hope Unity Devs make the variable in question public in the Service Menu though, so editing the actual asset to prevent automatic initialization is not required anymore.
Hello, @pareshkh thank for your code snippet. After the fix, you do not need manually listen for a connection. Please, try to Initialize on start and let Ads SDK handle it.
I am using unity ads in my android game. When the internet is connected from starting of the game then the ads are shown and when internet is not connected from starting and then started in-between the game then ads are shown. But the problem is if the internet connection is lost in-between the game and regain then the ads are not shown. Please help me i am struggling with it.
@coolamigo Which version of the SDK are you using? If the SDK is initialised and fails due to a connection issue, it is supposed to retry until it finds a valid connection.