D
D
dark_spectator2018-12-25 01:20:18
C++ / C#
dark_spectator, 2018-12-25 01:20:18

App crash when showing ads?

Introduced advertising into the application, everything is fine in the editor, but when building apk and draining it to the phone, when the ad loading is triggered, the application crashes. How can this be fixed?

using UnityEngine;
using GoogleMobileAds.Api;

public class BonuseHelper : MonoBehaviour {

    private const string appID = "ca-app-pub-8281650214845744~2700892211";
    private const string adId = "ca-app-pub-8281650214845744/9046808711";
    

    private void Awake()
    {
        MobileAds.Initialize(appID);
    }

    // Use this for initialization
    void Start()
    {

        
    }

    public void ShowAD()
    {
        InterstitialAd ad = new InterstitialAd(adId);
        AdRequest request = new AdRequest.Builder().AddTestDevice(AdRequest.TestDeviceSimulator).AddTestDevice("3ED655EC9754A480").Build();
        ad.LoadAd(request);
        ad.Show();
    }

    // Update is called once per frame
    void Update()
    {

    }

}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Gaydak, 2018-12-25
@dark_spectator

https://developers.google.com/admob/unity/interstitial

Show the ad
Interstitial ads should be displayed during natural pauses in the flow of an app. Between levels of a game is a good example, or after the user completes a task. To show an interstitial, use the isLoaded() method to verify that it's done loading, then call show().
at least, do not call the display without checking)
and definitely not immediately .. let something load ..
in the documentation, the example clearly shows.

V
Vitaliy Orlov, 2018-12-25
@orlov0562

wrap the ad display in a try catch and see what's wrong

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question