Anand
Anand

Reputation: 1959

Xamarin forms ios app rejected due to Deprecated API Usage UIWebView

I have a xamarin.forms app which have a webview. Whenever I try to publish the app to apple app store I get the Deprecated API Usage UIWebView warning and my app gets rejected. I saw the issue raised in https://github.com/xamarin/Xamarin.Forms/issues/7323. But I could't fix my issue. I replaced the webView using this render.

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

On ios part

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

I also added --optimize=experimental-xforms-product-type as additional mtouch arguments and published the app. Still got rejected. How to solve this issue? Any help is appreciated.

My xamarin.forms verion :4.6.0.847

xamarin.ios version : 13.16.0.13

Upvotes: 0

Views: 445

Answers (1)

Saamer
Saamer

Reputation: 5099

Couldn't post this as a comment, because I wanted to share a picture.

This happened to me before too, where I set --optimize=experimental-xforms-product-type but I still got that error.

My issue was that I set those additional mtouch arguments for the wrong configuration. As you can see in the image, make sure you are placing those values in the right configuration and platform! It should be the same combination that you use for creating the archive: Visual Studio screenshot showing the iOS Project options

Upvotes: 1

Related Questions