C# 获得';MediationRewardedVideoAdListenerImplementor不是抽象的,并且不重写抽象方法';尝试在xamarin表单中使用admob时
C# 获得';MediationRewardedVideoAdListenerImplementor不是抽象的,并且不重写抽象方法';尝试在xamarin表单中使用admob时,c#,android,ios,xamarin.forms,admob,C#,Android,Ios,Xamarin.forms,Admob,MediationRewardedVideoAdListener实现器不是抽象的,并且不重写MediationRewardedVideoAdListener中的抽象方法zzc(Bundle) 公共类MediationRewardedVideoAdListenerImplementor SocialFeedTest.Android C:\Users\blain\source\repos\SocialFeedTest\SocialFeedTest\SocialFeedTest.Android\obj
MediationRewardedVideoAdListener实现器不是抽象的,并且不重写MediationRewardedVideoAdListener中的抽象方法zzc(Bundle)
公共类MediationRewardedVideoAdListenerImplementor SocialFeedTest.Android C:\Users\blain\source\repos\SocialFeedTest\SocialFeedTest\SocialFeedTest.Android\obj\Debug\90\Android\src\mono\com\google\Android\gms\ads\reward\mediation\MediationRewardedVideoAdListenerImplementor.java 4
下面是本教程。这对我来说是很难诊断的,因为它不会在我的代码中的行号上中断,它说错误出现在我不理解的自动生成的代码中。它也没有说我的代码中有错误,但它不会让我构建或模拟它
这是我的密码
xamarin.forms
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace SocialFeedTest.Control
{
public class AdMobView : View
{
public static readonly BindableProperty AdUnitIdProperty = BindableProperty.Create(
nameof(AdUnitId),
typeof(string),
typeof(AdMobView),
string.Empty);
public string AdUnitId
{
get => (string)GetValue(AdUnitIdProperty);
set => SetValue(AdUnitIdProperty, value);
}
}
}
安卓
渲染器
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.Gms.Ads;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using SocialFeedTest.Control;
using SocialFeedTest.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(AdMobView), typeof(AdMobViewRenderer))]
namespace SocialFeedTest.Droid
{
public class AdMobViewRenderer : ViewRenderer<AdMobView, AdView>
{
public AdMobViewRenderer(Context context) : base(context) { }
protected override void OnElementChanged(ElementChangedEventArgs<AdMobView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null && Control == null)
SetNativeControl(CreateAdView());
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == nameof(AdView.AdUnitId))
Control.AdUnitId = Element.AdUnitId;
}
private AdView CreateAdView()
{
var adView = new AdView(Context)
{
AdSize = AdSize.SmartBanner,
AdUnitId = Element.AdUnitId
};
adView.LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
adView.LoadAd(new AdRequest.Builder().Build());
return adView;
}
}
}
ios
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用System.Linq;
使用系统文本;
使用基础;
使用Google.MobileAds;
使用社会反馈测试。控制;
使用SocialFeedTest.iOS;
使用UIKit;
使用Xamarin.Forms;
使用Xamarin.Forms.Platform.iOS;
[程序集:ExportRenderer(typeof(AdmObjView)、typeof(AdmObjViewRenderer))]
名称空间SocialFeedTest.iOS
{
公共类AdMobViewRenderer:ViewRenderer
{
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
if(Control==null)
{
SetNativeControl(CreateBannerView());
}
}
受保护的覆盖无效OnElementPropertyChanged(对象发送方,PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(发送方,e);
if(e.PropertyName==nameof(BannerView.AdUnitId))
Control.AdUnitId=Element.AdUnitId;
}
私有BannerView CreateBannerView()
{
var bannerView=新的bannerView(AdSizeCons.SmartBannerPortrait)
{
AdUnitId=元素。AdUnitId,
RootViewController=GetVisibleViewController()
};
bannerView.LoadRequest(GetRequest());
请求GetRequest()
{
var request=request.GetDefaultRequest();
返回请求;
}
返回横幅视图;
}
私有UIViewController GetVisibleViewController()
{
var windows=UIApplication.SharedApplication.windows;
foreach(windows中的var窗口)
{
if(window.RootViewController!=null)
{
返回window.RootViewController;
}
}
返回null;
}
}
}
主要的
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用基础;
使用UIKit;
名称空间SocialFeedTest.iOS
{
公共类应用程序
{
//这是应用程序的主要入口点。
静态void Main(字符串[]参数)
{
//如果要使用与“AppDelegate”不同的应用程序委托类
//您可以在这里指定它。
Main(args,null,“AppDelegate”);
}
}
}
如果您使用的是该版本,则会出现编译警告,因为它不会因谷歌广告中的SDK更改而更新。
你的舱单现在应该有这个
元数据安卓:name=“com.google.android.gms.ads.APPLICATION\u ID”安卓:value=“ca-app-pub-xxxxxxxxx-xxxxxxxxx”
如果你只想要广告,我建议使用Xamarin.GooglePlayServices.Ads.Lite
您可以在这里看到如何操作。谢谢,它可以正常工作,没有生成错误。但是现在它在调试模式下显示为invisibleIn,需要一些时间才能显示,通常应该显示为测试横幅,记住根据新的SDKalso正确设置清单,所以有没有办法使用firebase来实现这一点。我使用firebase作为后端,并希望有分析,你可以添加firebase分析
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace SocialFeedTest.Droid
{
[Activity(Label = "SocialFeedTest", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Android.Gms.Ads.MobileAds.Initialize(ApplicationContext, "ca-app-pub-5184019642309342~9928782520");
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Foundation;
using Google.MobileAds;
using SocialFeedTest.Control;
using SocialFeedTest.iOS;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(AdMobView), typeof(AdMobViewRenderer))]
namespace SocialFeedTest.iOS
{
public class AdMobViewRenderer : ViewRenderer<AdMobView, BannerView>
{
protected override void OnElementChanged(ElementChangedEventArgs<AdMobView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
SetNativeControl(CreateBannerView());
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == nameof(BannerView.AdUnitId))
Control.AdUnitId = Element.AdUnitId;
}
private BannerView CreateBannerView()
{
var bannerView = new BannerView(AdSizeCons.SmartBannerPortrait)
{
AdUnitId = Element.AdUnitId,
RootViewController = GetVisibleViewController()
};
bannerView.LoadRequest(GetRequest());
Request GetRequest()
{
var request = Request.GetDefaultRequest();
return request;
}
return bannerView;
}
private UIViewController GetVisibleViewController()
{
var windows = UIApplication.SharedApplication.Windows;
foreach (var window in windows)
{
if (window.RootViewController != null)
{
return window.RootViewController;
}
}
return null;
}
}
}
main
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
namespace SocialFeedTest.iOS
{
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, "AppDelegate");
}
}
}