Admob广告无法在Unity 5.3.5p7个人版中使用

时间:2016-07-18 08:26:35

标签: unity3d admob

我正在使用这个Unity插件,但我无法接收广告。当我为iOS构建代码并运行它(使用Xcode)时,将发生下面的iPhone。我调用以下函数

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());
}

代码中的以下行:

interstitial = new InterstitialAd(adUnitId);

我在xcode日志中收到此错误:

  

NotSupportedException:要编组托管方法,请添加一个   属性名为'MonoPInvokeCallback'的方法定义。       在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       在GoogleMobileAds.Api.InterstitialAd..ctor(System.String adUnitId)[0x00000] in:0

以下是我的“播放器设置”屏幕截图 Player Settings 请帮帮我

1 个答案:

答案 0 :(得分:0)

您只需按照日志消息中的说明进行操作:

  

请在方法中添加名为“MonoPInvokeCallback”的属性   定义。在   GoogleMobileAds.iOS.Externs.GADUSetInterstitialCallbacks(IntPtr   插页式广告,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

在IOSInterstitialClient.cs中的回调之前添加[MonoPInvokeCallbac(type)]属性:

#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