- Home /
Can't connect to unityAds, if internet connection is gained after game has started
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
So, any solutions?
Answer by TofuS · Oct 12, 2016 at 06:03 AM
Did you find a fix to this? I'm having same problem
which Unity version are you using? (if you are not posting an answer, you should comment not reply)
I was using Unity version 5.3.4 This would happen if the game started without any wifi or data, then later on if the user turned on their wifi or data, Unity ads would not initialise. Now i just updated my Unity to 5.3.6 Thanks for the reply!
Answer by graviton · Oct 17, 2016 at 09:59 PM
You'll need UnityAdsHelper (I had to change some things in the scripts to make it work with my version of Unity; if I'm remembering correctly).
You should be fine, with your version.
Get UnityAdsHelper here
https://github.com/Applifier/unity-ads-helper/wiki
Extra help here
https://forum.unity3d.com/threads/ad-not-ready-and-data-connection.381577/#post-2480019
https://forum.unity3d.com/threads/cannot-disable-unityads-auto-initialization.402451/
found this example script
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);
}
}
}