[英]Xamarin forms custom WebViewRender on Android
我正在嘗試向WebView控制器中的每個請求添加一些標頭。 我正在使用自定義Web渲染器添加標題。 它在iOS上運行良好,但僅在Android中添加renderer類會導致異常。
代碼看起來像這樣
在PCL中,我繼承了WebView控件以添加一些自定義屬性
public class AuthWebView : WebView
{
public static readonly BindableProperty UrlProperty =
BindableProperty.Create("Url", typeof(string), typeof(AuthWebView), default(string));
public string Url
{
get => (string)GetValue(UrlProperty);
set => SetValue(UrlProperty, value);
}
public string UserToken { get; set; }
}
在android項目中,我只創建了一個空白渲染,如下所示
[assembly: ExportRenderer(typeof(AuthWebView), typeof(TestRenderer))]
namespace Reshare.Droid
{
public class TestRenderer : WebViewRenderer
{
}
}
每當嘗試啟動包含AuthWebView控件的頁面時,我都會收到一個通用異常
未處理的異常:System.Reflection.TargetInvocationException:目標調用已引發異常
我在這里錯過的任何事情都可能導致異常發生嗎?
該問題似乎與Xamarin.Forms包的舊版本有關,並且在我將nuget包更新到最新版本時才解決。
僅供參考,如果有人遇到過此問題,我正在使用Xamarin.Forms.2.4.0.38779 ,現在更新為版本Xamarin.Forms.2.5.0.91635 ,我使用的是此處詳細介紹的方法https://developer.xamarin.com/指南/ xamarin-forms /應用程序基礎知識/ custom-renderer / hybridwebview /
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.