首页 > 解决方案 > Xamarin 表单 ios 应用程序由于已弃用的 API 使用 UIWebView 而被拒绝

问题描述

我有一个带有 webview 的 xamarin.forms 应用程序。每当我尝试将应用程序发布到苹果应用商店时,我都会收到Deprecated API Usage UIWebView警告并且我的应用程序被拒绝。我在https://github.com/xamarin/Xamarin.Forms/issues/7323中看到了这个问题。但我无法解决我的问题。我用这个渲染替换了 webView。

  public class MyWebView : WebView
    {
        public static readonly BindableProperty UrlProperty = BindableProperty.Create(
            propertyName: "Url",
            returnType: typeof(string),
            declaringType: typeof(MyWebView),
            defaultValue: default(string));

        public string Url
        {
            get { return (string)GetValue(UrlProperty); }
            set { SetValue(UrlProperty, value); }
        }
    }

在 ios 部分

[assembly: ExportRenderer(typeof(MyWebView), typeof(MyWebViewRenderer))]
namespace WKWebViewDemo.iOS
{
    public class MyWebViewRenderer : ViewRenderer<MyWebView, WKWebView>
    {
        WKWebView _wkWebView;
        protected override void OnElementChanged(ElementChangedEventArgs<MyWebView> e)
        {
            base.OnElementChanged(e);

            if (Control == null)
            {
                var config = new WKWebViewConfiguration();
                _wkWebView = new WKWebView(Frame, config);
                SetNativeControl(_wkWebView);
            }
            if (e.NewElement != null)
            {
                Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Url)));
            }
        }
    }
}

我还添加了 --optimize=experimental-xforms-product-type作为附加的 mtouch 参数并发布了应用程序。还是被拒绝了。如何解决这个问题?任何帮助表示赞赏。

我的 xamarin.forms 版本:4.6.0.847

xamarin.ios 版本:13.16.0.13

标签: xamarinxamarin.formsxamarin.ios

解决方案


无法将此作为评论发布,因为我想分享一张照片。

这也发生在我之前,我设置的地方,--optimize=experimental-xforms-product-type但我仍然得到那个错误。

我的问题是我为错误的配置设置了这些额外的 mtouch 参数。正如您在图像中看到的,确保将这些值放置在正确的配置和平台中!它应该与您用于创建存档的组合相同: 显示 iOS 项目选项的 Visual Studio 屏幕截图


推荐阅读