Admob ads not working in Unity 5.3.5p7 personal

unity3d admob

379 просмотра

1 ответ

1 Репутация автора

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

Автор: Zeeshan Arif Источник Размещён: 18.07.2016 08:26

Ответы (1)


0 плюса

6956 Репутация автора

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
Автор: Umair M Размещён: 18.07.2016 10:51
Вопросы из категории :
32x32