HttpListener used on Xamarin.IOS app. "Safari cant open the page because it couldn't connect to the server" error only on iOS 17 devices.

ZNXJH 5 Reputation points

Our project uses the latest Xamarin and our app has a function that creates a HTTP server to store a html and config file, and we use SfSafariViewController to view the contents on the html file. However, after the release of iOS17, this function does not work as intended. Safari was opened but could not connect to the localhost.

Question: is the creation of a localhost server using HttpListener blocked by Safari?

We want to view the contents on an in-app browser, and we are looking at using WKWebView as an alternative but we are open to more suggestions.

== Starting the server ==

using System.Net;

static HttpListener _httpListener = new HttpListener();



== Viewing the contents on Safari ==

var sfViewController = new SFSafariViewController(new NSUrl($"http://localhost:8000/test.html")

// vc has a class type of UIViewController

vc.PresentViewController(sfViewController, true, null);

== Outcome ==

Safari opened and display: “Safari can’t open the page because it couldn’t connect to the server”

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,206 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 23,306 Reputation points Microsoft Vendor


    iOS 17 will not be supported with Xamarin. Xcode 14 SDKs (iOS and iPadOS 16, macOS 13) will be the final versions Xamarin targets. Please see Xamarin Support Policy.

    I addition, you should specify a server address instead of localhost. And the "Http://localhost" request is considered as a non-secure site, you could try adding NSAllowsLocalNetworking to the Info.plist file.

        <key> NSAllowsLocalNetworking</key>

    Or disable ATS by adding NSAllowsArbitraryLoads key.


    Or specific domain to bypass ATS. See App Transport Security in Xamarin.iOS - Xamarin | Microsoft Learn

    Best Regards,

    Wenyan Zhang

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.