UnityAds won't initialize if app started offline

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’m having the same problem. I found this thread from a while back: What to do when Network is unavailable - Unity Services - Unity Discussions

The IsReady() solution he ran into doesn’t seem to apply anymore. I’m using the UnityAdsHelper code as well.

I gave it a shot on Crossy Road and they somehow handle the initializing after first being offline.

I’ve also tried updating to the Unity Ads SDK 1.5.0 and still can’t get it to initialize after starting offline then going online.

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.

Thanks for feedback.

/Rasmus

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.

Hi,

I’m using Unity Ads in 5.2 (integrated) and I’m having the same problem. Will this be fixed in next patch?

I described a workaround here to be able to manually initialize Unity Ads in 5.2:
http://forum.unity3d.com/threads/issues-in-migrating-to-5-2.353849/#post-2295957

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.

-act

1 Like

Thank you actraiser3, that actually worked.

this issue is still remain in current sdk version. plz do something as early as possible.

Hello @pareshkh thanks for your feedback. We have fixed fixed it in the latest versions of the SDK. In which version are you able to reproduce it?

thank @denisas for quick reply. but issue is still remain. after update on current version.

my test ads code.

public class TestAdsScript : MonoBehaviour {

public string adsId = “MY_APS_ID”;
public bool connected;

void Start()
{
StartCoroutine(tryToConnect());
}

IEnumerator tryToConnect()
{
//wait for networkconnection
while(Application.internetReachability == NetworkReachability.NotReachable)
yield return null;

//after device reach network. wait for 5sec for ensure initialize proper.
Invoke(“inst”, 5);
}

void inst()
{
// after double check network connection finally ini. id.
Advertisement.Initialize(adsId, true);

StartCoroutine(ShowAdWhenReady());
}

IEnumerator ShowAdWhenReady()
{
while (!Advertisement.IsReady())
yield return null;

Advertisement.Show();
}
}

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.

In my recent project and newly installed Unity and other tools, I am getting these errors whenever internet is turned off.

Invalid configuration request for gameId: 3561129
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback()

Error: NameResolutionFailure
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback()

Please help as I need to upload ASAP
I am using this code

string gameId = “3561129”;
string placement = “rewardedVideo”;
bool testMode = true;
void Start()
{

Advertisement.AddListener(this);
Advertisement.Initialize(gameId, testMode);
}

public void rewardAdClicked()
{
flagAd = true;
Advertisement.Show(placement);
}

public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
MovControl.lives = 1;
}

Someone needs to reply this, I am not getting this information elsewhere

@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.

I think it is 26.1.1, If you can assist, I will recheck. If you can please also look at the new post I made for the issue here:

It explains in more detail what issues I am facing. I have received no responses this far.

@coolamigo The latest version of the Ads SDK is 3.4.4 so I think you might have accidentally gotten the wrong version number there.

Have you installed the SDK via the package manager or asset store? If you are not already on the latest version I recommend you upgrade.

I think I tried both, this is my first project actually, could someone tell me how I check the version