简体   繁体   中英

Admob ads not working in Unity 5.3.5p7 personal

I'm using this unity plugin but I'm not able to receive ads. When I build the code for iOS and run it on (using Xcode) iPhone below will happen. I call the below function

private static InterstitialAd interstitial;
public void RequestInterstitial()
{
     string adUnitId = "inter_admob_id";
     // Create an interstitial.
     interstitial = new InterstitialAd(adUnitId);
     // Load an interstitial ad.
     interstitial.LoadAd(createAdRequest());
}

On following line in the code:

interstitial = new InterstitialAd(adUnitId);

I receive this error in xcode logs:

NotSupportedException: To marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition. at GoogleMobileAds.iOS.Externs.GADUSetInterstitialCallbacks (IntPtr interstitial, GoogleMobileAds.iOS.GADUInterstitialDidReceiveAdCallback adReceivedCallback, GoogleMobileAds.iOS.GADUInterstitialDidFailToReceiveAdWithErrorCallback adFailedCallback, GoogleMobileAds.iOS.GADUInterstitialWillPresentScreenCallback willPresentCallback, GoogleMobileAds.iOS.GADUInterstitialDidDismissScreenCallback didDismissCallback, GoogleMobileAds.iOS.GADUInterstitialWillLeaveApplicationCallback willLeaveCallback) [0x00000] in :0 at GoogleMobileAds.Api.InterstitialAd..ctor (System.String adUnitId) [0x00000] in :0

Below is my "Player Setting" screenshot Player Settings Please help me out

You just have to do as instructed in Log message:

please add an attribute named 'MonoPInvokeCallback' to the method definition. at GoogleMobileAds.iOS.Externs.GADUSetInterstitialCallbacks (IntPtr interstitial, GoogleMobileAds.iOS.GADUInterstitialDidReceiveAdCallback adReceivedCallback, GoogleMobileAds.iOS.GADUInterstitialDidFailToReceiveAdWithErrorCallback adFailedCallback, GoogleMobileAds.iOS.GADUInterstitialWillPresentScreenCallback willPresentCallback, GoogleMobileAds.iOS.GADUInterstitialDidDismissScreenCallback didDismissCallback, GoogleMobileAds.iOS.GADUInterstitialWillLeaveApplicationCallback willLeaveCallback) [0x00000] in :0 at GoogleMobileAds.Api.InterstitialAd..ctor (System.String adUnitId) [0x00000] in :0

Add [MonoPInvokeCallbac(type)] attributes before callbacks in IOSInterstitialClient.cs :

#region Banner callback methods

[MonoPInvokeCallback(typeof(GADUInterstitialDidReceiveAdCallback))]
private static void InterstitialDidReceiveAdCallback(IntPtr interstitialClient)
{
    IntPtrToInterstitialClient(interstitialClient).listener.FireAdLoaded();
}

[MonoPInvokeCallback(typeof(GADUInterstitialDidFailToReceiveAdWithErrorCallback))]
private static void InterstitialDidFailToReceiveAdWithErrorCallback(
        IntPtr interstitialClient, string error)
{
    IntPtrToInterstitialClient(interstitialClient).listener.FireAdFailedToLoad(error);
}

[MonoPInvokeCallback(typeof(GADUInterstitialWillPresentScreenCallback))]
private static void InterstitialWillPresentScreenCallback(IntPtr interstitialClient)
{
    IntPtrToInterstitialClient(interstitialClient).listener.FireAdOpened();
}

[MonoPInvokeCallback(typeof(GADUInterstitialWillDismissScreenCallback))]
private static void InterstitialWillDismissScreenCallback(IntPtr interstitialClient)
{
    IntPtrToInterstitialClient(interstitialClient).listener.FireAdClosing();
}

[MonoPInvokeCallback(typeof(GADUInterstitialDidDismissScreenCallback))]
private static void InterstitialDidDismissScreenCallback(IntPtr interstitialClient)
{
    IntPtrToInterstitialClient(interstitialClient).listener.FireAdClosed();
}

[MonoPInvokeCallback(typeof(GADUInterstitialWillLeaveApplicationCallback))]
private static void InterstitialWillLeaveApplicationCallback(IntPtr interstitialClient)
{
    IntPtrToInterstitialClient(interstitialClient).listener.FireAdLeftApplication();
}

private static IOSInterstitialClient IntPtrToInterstitialClient(IntPtr interstitialClient)
{
    GCHandle handle = (GCHandle) interstitialClient;
    return handle.Target as IOSInterstitialClient;
}

#endregion

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