I’m using unityAds, and I ran into a an issue with Ad initialization.
If the game is started with no internet connection, it fails to initialize Ads.
This makes sense, however Ads never initialize, even if an internet connection is gained at some point during the game, unless the whole game is restarted with an internet connection.
I’m using Unity 5.1.2f1, and the fixes in Unity 5.3 don’t help me
using UnityEngine;
using System.Collections;
public class InternetConnectionCheckExample : MonoBehaviour
{
private bool unityAdsInitialized = false;//can be used for informing the user about the status
// Use this for initialization
void Awake ()
{
StartCoroutine("checkInternetConnection");
}
public IEnumerator checkInternetConnection()
{
float timeCheck = 2.0f;//will check google.com every two seconds
float t1;
float t2;
while(!unityAdsInitialized)
{
WWW www = new WWW("http://google.com");
t1 = Time.fixedTime;
yield return www;
if (www.error == null)//if no error
{
#if UNITY_ANDROID
//Advertisement.Initialize(androidGameID); // initialize Unity Ads.
UnityAdsHelper.Initialize(); // initialize Unity Ads.
#elif UNITY_IOS
UnityAdsHelper.Initialize(); // initialize Unity Ads.
#endif
unityAdsInitialized = true;
break;//will end the coroutine
}
t2 = Time.fixedTime - t1;
if(t2 < timeCheck)
yield return new WaitForSeconds(timeCheck - t2);
}
}
}