[英]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.
当我为iOS构建代码并在(使用Xcode)上运行它时,将发生以下iPhone。 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: 我在xcode日志中收到此错误:
NotSupportedException: To marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition.
NotSupportedException:要封送托管方法,请在方法定义中添加一个名为“ MonoPInvokeCallback”的属性。 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
在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]在:0处的GoogleMobileAds.Api.InterstitialAd..ctor(System.String adUnitId)[0x00000]在: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.
请在方法定义中添加一个名为“ MonoPInvokeCallback”的属性。 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
在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]在:0处的GoogleMobileAds.Api.InterstitialAd..ctor(System.String adUnitId)[0x00000]在:0处
Add [MonoPInvokeCallbac(type)]
attributes before callbacks in IOSInterstitialClient.cs : 在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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.