简体   繁体   中英

Admob Native Ad convert Issue

I am using google Admob Native Ad to target specific locations in a game. While following the steps, I encountered the following error:

 AdMobManager.cs(37,30): error CS1503: Argument 1: cannot convert from 'string' to 'System.Action<GoogleMobileAds.Api.InitializationStatus>'

The following is where the error is occurring on Mobile.Initialize:

 private string idApp, idNative;

// Start is called before the first frame update
void Start(){
    idApp = "ca-app-pub-3940256099942544~3347511713";
    idNative = "ca-app-pub-3940256099942544/2247696110";

   MobileAds.Initialize(idApp);
   RequestNativeAd();
}

It looks like initalize does not take a string argument. It takes a Context though. The value you are putting into initialize currently should go somewhere in a Context . Here are the variables for a Context class: https://developer.android.com/reference/android/content/Context.html

You should change it to something like:

private string idApp, idNative;

private Context initContext;

// Start is called before the first frame update
void Start(){
   idApp = "ca-app-pub-3940256099942544~3347511713";
   idNative = "ca-app-pub-3940256099942544/2247696110";
   initContext = new();

   initContext./*...*/ = idApp;
   initContext./*...*/ = idNative;
   MobileAds.Initialize(initContext);
   RequestNativeAd();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM