About WebView in Xamarin.form

Asked 2 years ago, Updated 2 years ago, 95 views

I am having trouble with the Xamarin.form WebView.
I am trying to implement a webview tag in xaml and display an Amazon page as an example.

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage 
		xmlns="http://xamarin.com/schemas/2014/forms"
		xmlns: x="http://schemas.microsoft.com/winfx/2009/xaml"
		x: Class="SampleClass.Amazon"
		xmlns: i18n = "clr-namespace: SampleClass; assembly=SampleClass"
		Title="{i18n:Translate Amazon}">
	
	<AbsoluteLayout>
		<WebView Source="{StaticResource AmazonURL}"
			AbsoluteLayout.LayoutBounds = "0,0,1,1"
			AbsoluteLayout.LayoutFlags="All"/>
	</AbsoluteLayout>

</ContentPage>

"Also, ""AmazonURL"" in the code is defined in ""App.xaml""

"

<x:String x:Key="AmazonURL">http://amzn.to/1UKGpN9</x:String>

Now, when I check the actual machine and simulator (iOS), it doesn't show as follows:

Do not display Amazon web pages

The following page is displayed in Safari.

Safari View

After checking, it does not appear in shortened URLs, but in normal URLs.
Usually, the string is longer at the URL, so to display it as a shortened URL
What should I do?
Professor, please.

webview xaml xamarin

2022-09-30 21:16

1 Answers

"App Transport Security has blocked a cleartext HTTP" error appears.

If you search Google, you will find out the cause.

In this Info.plist configuration example, "Enable ATS by default and list domains not covered by ATS in Info.plist" I would add the following to the Info.plist file under the XXX.iOS project (I personally think it would be easier to edit with a text editor):

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>amzn.to</key>
        <dict>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

You should now be allowed to connect to amzn.to and be able to view it in WebView.


2022-09-30 21:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.