Unable to Resolve Deprecation of UIWebView warning while uploading Xamarin application - xamarin

I Have followed the blog https://devblogs.microsoft.com/xamarin/uiwebview-deprecation-xamarin-forms/ to remove the UIWebView dependency in my project.
According to the document
1)xamarin.forms version is 4.6
2)xamarin.ios version is 13.20
3)I added the command in mtouch Arguments and linker is link All
I still got warning while upoading build to test flight
I then followed this document https://learn.microsoft.com/en-us/xamarin/ios/release-notes/13/13.16#help-with-uiwebview-deprecation where we can find out whether UIWebView is still being used in our application.I am getting below in the build output.
MTOUCH : warning MT1502: One or more reference(s) to type 'UIKit.UIWebView' already exists inside 'Xamarin.Forms.Platform.iOS, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' before linking
I am not sure why there is reference in Xamarin.Forms.Platform.iOS as xamarin package is updated to 4.6 as per the blog.
Can anyone please help me to get rid of this warning?

Please follow this link
simply go to your iOS project, open the project properties and add this flag in the
'additional mtouch arguments field: --optimize=experimental-xforms-product-type' in your

Use WKWebView instead of UIWebView. UIWebView has been deprecated and Now The App Store will no longer accept new apps using UIWebView as of April 2020.
using System.IO;
using CustomRenderer;
using CustomRenderer.iOS;
using Foundation;
using UIKit;
using WebKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(CustomWebView), typeof(WebViewRender_iOS))]
namespace CustomRenderer.iOS
{
public class WebViewRender_iOS : WkWebViewRenderer
{
WKUserContentController userController;
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
userController.RemoveAllUserScripts();
userController.RemoveScriptMessageHandler("invokeAction");
CustomWebView hybridWebView = e.OldElement as CustomWebView;
hybridWebView.Cleanup();
}
if (e.NewElement != null)
{
CustomWebView hybridWebView = e.NewElement as CustomWebView;
LoadRequest(new NSUrlRequest(new NSUrl(hybridWebView._WebURI)));
}
}
}
}

There are a few different changes that need to be made for the deprecation warning to go away.
The build configuration used to upload to the store (Release|iPhone, App Store|iPhone, etc.) in iOS Build section needs the following additional mtouch arguments --optimize=experimental-xforms-product-type
The app needs to use Xamarin.Forms version >= 4.5 or >= 4.6 if using Material Visual
It also needs to be using Xamarin.iOS 13.10.0.17 or higher, which is included with Visual Studio for Mac 8.4.1 and Visual Studio 16.4.3.
Remove all references to UIWebView in the codebase
More info is included in the docs and if that doesn't resolve the issue the app may be using a third-party library with a reference to UIWebView that either needs updating to a version without it or removed altogether from the app.

Thank you all for your suggestions. Below is what worked for me.
Follow the 3 steps mentioned in
https://devblogs.microsoft.com/xamarin/uiwebview-deprecation-xamarin-forms/
Run grep -r UIWebview . on repository level. It will show the list of references in .sln and third party packages
Remove or update third party libraries. Igore bin and obj folders
For Me, I had to
1.Remove deprecated scanbot.xamarin.ios SDK and add scanbot.xamarin pkg
2.Remove hockey app SDK as it was deprecated and didn’t have any updates
3.Remove googleanalytics SDK as it wasn’t being used in the project

Related

Mapbox Navigation Xamarin Bindings - AAR errors "does not implement interface IComparator.Compare"

I have created all my .gradle files (.jar and .aar) through Android Studio.
The .jar files compile to .dll files through the android bindings in Xamarin without any issues - and I can expand them in object explorer Visual Studio when including them as references.
My problem is with the .aar files.
I have the mapbox-android-core-1.4.0.aar file from the gradle in my Jars folder in Visual Studio.
The build action is set to "LibraryProjectZip" and under references I have included Xamarin.Android.Support.v7.AppCompat which then included all other android support dependencies.
The Android Compile version is Android 9.0
Android class parser: class-parse
Android codegen target: XAJavaInterop1
When I build i get the following error:
Error CS0535 'FileUtils.LastModifiedComparator' does not implement interface member 'IComparator.Compare(Object, Object)'
The official Xamarin troublehsooting says I must add the managed return to metadata which I did as follows:
<attr path="/api/package[#name='com.mapbox.android.core']/class[#name='FileUtils']/method[#name='FileUtils.LastModifiedComparator']" name="managedReturn">java.lang.Object</attr>
With this added it still has exactly the same error, so I am not sure where I am going wrong.
Do I need to add a partial class to Additions or is the attr> above sufficient - just using the wrong information inside it, or am I missing what the error is in the first place?
Error CS0535 'FileUtils.LastModifiedComparator' does not implement interface member 'IComparator.Compare(Object, Object)'
To fix this issue, try to add a partial class declaration for 'LastModifiedComparator' class and explicitly implement IComparator.Compare(Object, Object):
public partial class DeviceService
{
public void Compare(object a, object b)
{
...
}
}
In your case, the method name in <attr ...> tag should be Compare instead of the 'LastModifiedComparator' method.
Check the tutorial:
https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/troubleshooting-bindings#possible-causes-6
Similar issue:
error CS0535 Class does not implement interface member

Null exception namespace App in Xamarin for UWP

I am developing UWP app in xamarin. The application works on IOS, Mac , Android, Windows. I have created UWP project in it according to the tutorial given in developer.xamarin.com. But it giving error saying Accessibility.App namespace not found.
Here is my code:
namespace Accessibility.UWP
{
public sealed partial class MainPage
{
public MainPage()
{
this.InitializeComponent();
this.LoadApplication(new Accessibility.App());
}
}
}
According to your description, the app can't see Accessibility.App. As you claim that Android and iOS projects work there are two things that can cause the problem:
you don't have the reference to your Shared/PCL project in your UWP project (most likely).
you have possibly changed the namespace / class name in the Shared/PCL project to something else than Accessibility.App
This is usually caused by missing reference to the shared project or class library where Xamarin.Forms App class resides. From the description this project should be called Accessibility.
Right-click the UWP project select Add, Reference... then in Solution tab select the Accessibility project.
Also it might happen that the UWP project didn't pick up on the reference, so restarting Visual Studio might help as well.
If all fails, you can try to use class name binding with using. On top of the source code file add:
using FormsApp = Accessibility.App;
And then in code use:
this.LoadApplication(new FormsApp());

How to migrate a Xamarin.Forms+Prism app to DryIoC from Unity?

I'm trying to change the container to DryIOC of a Xamarin.Forms + Prism app.
Visual studio is compiling and starting the app without errors, but when the app starts it doesn't fire App.OnInitialized method keeping the app on a blank screen.
What did I do?
Removed Prism.Unity, Unity and Microsoft related packages from the Android and Shared projects
Added DryIoc.dll (v2.10.7) and Prism.DryIoc.Forms (v6.3.0.1) packages to Android and Shared projects
Changed prism xmlns in App.xaml pointing to:
xmlns:prism="clr-namespace:Prism.DryIoc;assembly=Prism.DryIoc.Forms"
Changed the AndroidInitializer class in MainActivity.cs to:
public class AndroidInitializer : IPlatformInitializer
{
public void RegisterTypes(IContainer container)
{}
}
I created a blank app using the Prism DryIoC template and it works fine. Also, I compared the App.xaml, App.xaml.cs and MainActivity.cs files with those in my project and everything is OK.
What else can I do?
If you're converting over you'll need to do the following:
1) Remove the following three packages
- Prism.Unity.Forms
- Unity
- CommonServiceLocator
2) Update the xml namespace to clr-namespace:Prism.DryIoc;assembly=Prism.DryIoc.Forms in your App.xaml
3) Remove the Unity namespaces from your App.xaml.cs and replace them with Prism.DryIoc and DryIoc. Do the same in any IPlatformInitializer implementations, also changing IUnityContainer to IContainer
4) Update any service registrations since the signatures do not match between Unity and DryIoc.
5) Update any services or anything you specifically have that may directly use IUnityContainer to use IContainer.
6) Delete your obj and bin folders, clean and rebuild.
If you run into any trouble you can compare your project to either the Hamburger Menu or Tabbed Navigation samples.
UPDATE
Starting in Prism 7.2 the XML Namespace that is recommended for use is simply http://prismlibrary.com this will replace any clr-namespace declaration that you may have had previously and will work regardless of whether you are using an official Prism package or one of the Extended versions of Prism.
What worked for me was creating a new project using Prism DryIoC template and moving all my code it.

Conditional Compilation seems to be not working in Xamarin Studio

I created a Xamarin Forms app.
And inside a new page with a label named "MyLabel".
In the code behind for my page I have
private void SetUpUI()
{
#if __IOS__
this.MyLabel.BackgroundColor = Color.Navy;
#endif
}
In my iOS project options I can see symbol __IOS__ in the "Compiler" tab. (please see screenshot)
When I run in iOS it doesn't make the label blue:
But if I remove #if __IOS__ block it makes the label blue:
So it seems conditional compilation is not working.
I'm on a Mac. So couldn't test on Visual Studio.
Stuck with it for a long time but cannot figure out what I missed.
The answer of SushiHangover is correct: your PCL project won't have the compiler definitions for the platforms.
However, the solution he provides has become obsolete since Xamarin Forms 2.3.4 was released. Device.OnPlatform has been redesigned as discussed in this discussion and implemented in this Pull Request.
The correct way to do this in Xamarin Forms 2.3.4 and onwards is by using Device.RuntimePlatform. Use a switch or conditional to suit your needs like so:
if(Device.RuntimePlatform == Device.iOS)
{
// iOS
}
else if(Device.RuntimePlatform == Device.Android)
{
// Android
}
It would be possible to do it like you asked, if you were to use a shared project instead of a PCL. Because when you use a shared project, you have access to the compiler directives of your platform projects.
You are using the conditionals in your PCL project which would not contain those compiler defines, thus why your conditional code is greyed out.
In your PCL project you can use Device.OnPlatform to perform platform based processing:
Device.OnPlatform (iOS: () => this.MyLabel.BackgroundColor = Color.Navy; );
re: https://developer.xamarin.com/api/member/Xamarin.Forms.Device.OnPlatform/

In which package can I find Xamarin IDevice

I am writing a Xamarin Forms PCL application (both iOS and Android)
I have to pick an image from phone gallery.
I have read some documentation about this plugin:
Labs.Platform.Services.Media.MediaPicker
In my Common project, i have to put this code:
var device = Resolver.Resolve<IDevice>();
picker = DependencyService.Get<IMediaPicker>() ?? device.MediaPicker;
But I have an error on the first line: IDevice and Resolver Objects are not know. I think I am missing a reference or a using clause.
Thanks
You need to install the following Nuget package in all of your projects in the solution (i.e. PCL core project, iOS project, and the Android Project, and UWP project if using it):
https://www.nuget.org/packages/XLabs.Forms/
And you will need to add the following using statements:
using XLabs.Ioc;
using XLabs.Platform.Device;
using XLabs.Platform.Services.Media;

Resources