I switched from ads 3.7 to ads 4.0, I get the error "IsReady" and "resultcallback"

Hello
I switched from ads 3.7 to ads 4.0 i take this erors What should I change in my code to fix it? Can you share the corrected codes?

Codes

#if CHARTBOOST_ADS
using ChartboostSDK;
#endif
using System;
using System.Collections.Generic;
using SweetSugar.Scripts.Core;
using SweetSugar.Scripts.Integrations;
using UnityEngine;
#if GOOGLE_MOBILE_ADS
using GoogleMobileAds.Api;

#endif
#if UNITY_ADS
using UnityEngine.Advertisements;
#endif
namespace SweetSugar.Scripts.AdsEvents
{
    /// <summary>
    /// Ads manager responsible for initialization and showing
    /// </summary>
    public class AdsManager : UnityEngine.MonoBehaviour
    {
        public static AdsManager THIS;
        //EDITOR: ads events
        public List<AdEvents> adsEvents = new List<AdEvents>();
        //is unity ads enabled
        public bool enableUnityAds;
        //is admob enabled
        public bool enableGoogleMobileAds;
        //is chartboost enabled
        public bool enableChartboostAds;
        //rewarded zone for Unity ads
        public string rewardedVideoZone;
        //admob stuff
#if GOOGLE_MOBILE_ADS
        public InterstitialAd interstitial;
    private AdRequest requestAdmob;
#endif
        public string admobUIDAndroid;
        public string admobRewardedUIDAndroid;
        public string admobUIDIOS;
        public string admobRewardedUIDIOS;
        private AdManagerScriptable adsSettings;

        private void Awake()
        {
            if (THIS == null) THIS = this;
            else if(THIS != this)
            {
                Destroy(gameObject);
                return;
            }
            DontDestroyOnLoad(this);
            adsSettings = Resources.Load<AdManagerScriptable>("Scriptable/AdManagerScriptable");
            adsEvents = adsSettings.adsEvents;
            admobUIDAndroid = adsSettings.admobUIDAndroid;
            admobUIDIOS = adsSettings.admobUIDIOS;
#if UNITY_ADS//2.1.1
            enableUnityAds = true;
            var unityAds = Resources.Load<UnityAdsID>("Scriptable/UnityAdsID");
        #if UNITY_ANDROID
            Advertisement.Initialize(unityAds.androidID,false);
        #elif UNITY_IOS
            Advertisement.Initialize(unityAds.iOSID,false);
        #endif
#else
        enableUnityAds = false;
#endif
#if CHARTBOOST_ADS//1.6.1
        enableChartboostAds = true;
#else
            enableChartboostAds = false;
#endif
#if GOOGLE_MOBILE_ADS
        enableGoogleMobileAds =true;//1.6.1
#if UNITY_ANDROID
        MobileAds.Initialize(admobUIDAndroid);//2.1.6
        interstitial = new InterstitialAd(admobUIDAndroid);
#elif UNITY_IOS
        MobileAds.Initialize(admobUIDIOS);//2.1.6
        interstitial = new InterstitialAd(admobUIDIOS);
#else
        MobileAds.Initialize(admobUIDAndroid);//2.1.6
        interstitial = new InterstitialAd (admobUIDAndroid);
#endif

        // Create an empty ad request.
        requestAdmob = new AdRequest.Builder().Build();
        // Load the interstitial with the request.
        interstitial.LoadAd(requestAdmob);
        interstitial.OnAdLoaded += HandleInterstitialLoaded;
        interstitial.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
#else
            enableGoogleMobileAds = false;//1.6.1
#endif
        }
       
#if GOOGLE_MOBILE_ADS
   
    public void HandleInterstitialLoaded(object sender, EventArgs args)
    {
        print("HandleInterstitialLoaded event received.");
    }

    public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
        print("HandleInterstitialFailedToLoad event received with message: " + args.Message);
    }
#endif
       
        public bool GetRewardedUnityAdsReady()
        {
#if APPODEAL
        return AppodealIntegration.THIS.IsRewardedLoaded();
#endif
#if UNITY_ADS

            rewardedVideoZone = "rewardedVideo";
            if (Advertisement.IsReady(rewardedVideoZone))
            {
                return true;
            }
            else
            {
                rewardedVideoZone = "rewardedVideoZone";
                if (Advertisement.IsReady(rewardedVideoZone))
                {
                    return true;
                }
            }
#endif

            return false;
        }

        private void OnDisable()
        {
#if GOOGLE_MOBILE_ADS
            if (interstitial != null)
            {
                interstitial.OnAdLoaded -= HandleInterstitialLoaded;
                interstitial.OnAdFailedToLoad -= HandleInterstitialFailedToLoad;
            }

#endif
        }

        public delegate void RewardedShown();

        public static event RewardedShown OnRewardedShown;
        public void ShowRewardedAds()
    {
#if APPODEAL
        Debug.Log("show Rewarded ads video in " + LevelManager.THIS.gameStatus);

        if (GetRewardedUnityAdsReady())
        {
            AppodealIntegration.THIS.ShowRewardedAds();
        }
        else{
            #if UNITY_ADS
            Advertisement.Show(rewardedVideoZone, new ShowOptions
            {
                resultCallback = result =>
                {
                    if (result == ShowResult.Finished)
                    {
                        OnRewardedShown?.Invoke();
                        InitScript.Instance.ShowReward();
                    }
                }
            });
            #endif
        }
#elif UNITY_ADS
        Debug.Log("show Rewarded ads video in " + LevelManager.THIS.gameStatus);

        if (GetRewardedUnityAdsReady())
        {
            #if UNITY_ADS
            Advertisement.Show(rewardedVideoZone, new ShowOptions
            {
                resultCallback = result =>
                {
                    if (result == ShowResult.Finished)
                    {
                        OnRewardedShown?.Invoke();
                        InitScript.Instance.ShowReward();
                    }
                }
            });
            #endif
        }
//#elif GOOGLE_MOBILE_ADS//2.2
//        bool stillShow = true;
//#if UNITY_ADS
//        stillShow = !GetRewardedUnityAdsReady ();
//#endif
//        if(stillShow)
//        {
//            Debug.Log("show Admob Rewarded ads video in " + LevelManager.THIS.gameStatus);
//            RewAdmobManager.THIS.ShowRewardedAd(CheckRewardedAds);
//        }
#endif
    }

    public void CheckAdsEvents(GameState state)
    {   
        foreach (var item in adsEvents)
        {
            if (item.gameEvent == state)
            {
                item.calls++; 
                if (item.calls % item.everyLevel == 0)
                    ShowAdByType(item.adType);
            }
        }
    }

    void ShowAdByType(AdType adType)
    {
        if (adType == AdType.AdmobInterstitial && enableGoogleMobileAds)
            ShowAds(false);
        else if (adType == AdType.UnityAdsVideo && enableUnityAds)
            ShowVideo();
        else if (adType == AdType.ChartboostInterstitial && enableChartboostAds)
            ShowAds(true);
        else if(adType == AdType.Appodeal)
            ShowAds(false);
    }

    public void ShowVideo()
    { 
#if UNITY_ADS
        Debug.Log("show Unity ads video in " + LevelManager.THIS.gameStatus);

        if (Advertisement.IsReady("video"))
        {
            Advertisement.Show("video");
        }
        else
        {
            if (Advertisement.IsReady("defaultZone"))
            {
                Advertisement.Show("defaultZone");
            }
        }
#endif
    }

    public void CacheRewarded()
    {
#if APPODEAL
        AppodealIntegration.THIS.RequestRewarded();
#endif

    }


    public void ShowAds(bool chartboost = true)
    {
        #if APPODEAL
        if(AppodealIntegration.THIS.IsInterstitialLoaded())
        {
            Debug.Log("show  Interstitial in " + LevelManager.THIS.gameStatus);
            AppodealIntegration.THIS.ShowInterstitial();
        }
        #endif
        if (chartboost)
        {
#if CHARTBOOST_ADS
            Debug.Log("show Chartboost Interstitial in " + LevelManager.THIS.gameStatus);

            Chartboost.showInterstitial(CBLocation.Default);
            Chartboost.cacheInterstitial(CBLocation.Default);
#endif
        }
        else
        {
#if GOOGLE_MOBILE_ADS
            Debug.Log("show admob Interstitial in " + LevelManager.THIS.gameStatus);
            if (interstitial.IsLoaded())
            {
                interstitial.Show();
#if UNITY_ANDROID
                interstitial = new InterstitialAd(admobUIDAndroid);
#elif UNITY_IOS
                interstitial = new InterstitialAd(admobUIDIOS);
#else
                interstitial = new InterstitialAd (admobUIDAndroid);
#endif

                // Create an empty ad request.
                requestAdmob = new AdRequest.Builder().Build();
                // Load the interstitial with the request.
                interstitial.LoadAd(requestAdmob);
            }
#endif
        }
    }
    }
}

Erors

Önem Derecesi Kod Açıklama Proje Dosya Çizgi Gizleme Durumu
Hata CS0117 ‘Advertisement’ bir ‘IsReady’ tanımı içermiyor Assembly-CSharp C:\Users\Mert\Desktop\SweetCandyMatch3\Assets\SweetSugar\Scripts\AdsEvents\AdsManager.cs 119 Etkin
Hata CS0117 ‘Advertisement’ bir ‘IsReady’ tanımı içermiyor Assembly-CSharp C:\Users\Mert\Desktop\SweetCandyMatch3\Assets\SweetSugar\Scripts\AdsEvents\AdsManager.cs 126 Etkin
Hata CS0117 ‘ShowOptions’ bir ‘resultCallback’ tanımı içermiyor Assembly-CSharp C:\Users\Mert\Desktop\SweetCandyMatch3\Assets\SweetSugar\Scripts\AdsEvents\AdsManager.cs 183 Etkin
Hata CS0117 ‘Advertisement’ bir ‘IsReady’ tanımı içermiyor Assembly-CSharp C:\Users\Mert\Desktop\SweetCandyMatch3\Assets\SweetSugar\Scripts\AdsEvents\AdsManager.cs 237 Etkin
Hata CS0117 ‘Advertisement’ bir ‘IsReady’ tanımı içermiyor Assembly-CSharp C:\Users\Mert\Desktop\SweetCandyMatch3\Assets\SweetSugar\Scripts\AdsEvents\AdsManager.cs 243 Etkin

Start with the documentation to see how the API in question may have changed.

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly? Are you structuring the syntax correctly? Look for examples!

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

1 Like

Can you share the corrected codes with me?

Yes, some of APIs on version 3.X have been removed from version 4.0.0. For more details, please see the documentation here:
https://docs.unity.com/ads/en-us/manual/DeprecatedAPIClasses#Unity_(C#)

Can you sharefixxed codes with me ?