0
votes

I have a Xamarin Forms application using webview to load an external web page into it. The web page has links that the application needs to access. Android opens the links just fine but iOS does not. I've tried using Device.OpenUri(new Uri(e.Url)); but that opens the link in Safari within the webview. I only want the link that I clicked on to open in the webview.

2
Hi , welcome to so . I think you can navigation to a webview page in project when need to open a url . - Junior Jiang
Welcome to SO! You can also looking into this other way of launching webviews askxammy.com/customizing-browser-appearance-in-xamarin-forms - Saamer
Thanks Junior Jiang and Saamer for the reply and welcome. I don't think I'm explaining the problem correctly. On the web page that I set the webview source to are multiple links. In Android, clicking on a link would navigate the webview source to that page or at least I would say the app displays that links page. In iOS, clicking the link does nothing. - JRBowl-Ish
@JRBowl-Ish Hi , if answer be helpful , thanks for marking or voting up when you have time in advance *.^ - Junior Jiang

2 Answers

1
votes

Found the issue. My problem had to do with iOS not allowing website without https. For example if a link had google.com instead of https://google.com the app wouldn't allow it.

0
votes

You can create a ContentPage which contained WebView , then when click button , it can navigate to a WebView.

Create a WebPage :

public class WebPage : ContentPage
{
    public string urlstr { get; set; }
    WebView browser;
    public WebPage()
    {
        browser = new WebView();
        Content = browser;
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();
        browser.Source = urlstr;
        browser.Reload();
    }
}

In Previous Page , invoking the clicked method :

private void Button_Clicked(object sender, EventArgs e)
{
    WebPage webPage = new WebPage();
    webPage.urlstr = "https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/webview?tabs=windows";
    Navigation.PushAsync(webPage);
}

================================Update===================================

Yeah ,this problem should be about App Transport Security in iOS, you can have a look at it .

While Apple highly suggests using the HTTPS protocol and secure communication to internet based information, there might be times that this isn't always possible. For example, if you are communicating with a 3rd party web service or using internet delivered ads in your app.

If your Xamarin.iOS app must make a request to an insecure domain, the following changes to your app's Info.plist file will disable the security defaults that ATS enforces for a given domain:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
     <true/>
</dict>