Find file History
Latest commit d0ef8a5 Mar 13, 2018

id title brief sdk
Load a Web Page
This recipe shows how to load a web page in a UIWebView control.


To show a secure web page:

  1. Create a UIWebView and add it to a view:
webView = new UIWebView (View.Bounds);
  1. Load a URL using NSUrl and NSUrlRequest classes:
var url = ""; // NOTE: https secure request
webView.LoadRequest(new NSUrlRequest(new NSUrl(url)));

iOS 9 App Transport Security

The example code above uses an HTTPS URL. If the code was changed to the following:

var url = ""; // NOTE: http insecure request

Then the following error would appear (on iOS 9 and above) in the Application Output (if debugging) and the web view would remain blank:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.
Temporary exceptions can be configured via your app's Info.plist file.

To get around this issue you must use secure URLs or learn how to configure exceptions to App Transport Security (ATS) in the Info.plist file.

iOS 8 and earlier versions of iOS do not implement ATS. HTTP URLs will continue to work on earlier versions of iOS, and the Info.plist changes made for iOS 9 will be ignored.

Additional Information

By default the web page will open at its normal resolution. To scale it down so that the entire page width is visible set the ScalesPagesToFit property.

webView.ScalesPageToFit = true;