Muhammad Qais
Muhammad Qais

Reputation: 67

JavaScript not working in WKWebView in iOS

I am new to iOS and loading my website developed in jQuery Mobile to a WKWebView in Swift 4 and Xcode 9. After loading it inside a controller, I noticed that JavaScript is not called on some pages (for example, buttons that open the dialer to call and social sharing buttons don't work).

My code for loading the page:

let myURL = URL(string: "https://www.mySiteUrl.com")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)

Upvotes: 2

Views: 3449

Answers (1)

user3151675
user3151675

Reputation: 58029

It is likely that the JS scripts are from a non-HTTPS source and you left App Transport Security's Allow Arbitrary Loads disabled.

Here is how to fix that:

  1. Navigate to Project Settings/Target/[your app's target]/Info.

screenshot of Project Settings

  1. Check whether there is a dictionary called App Transport Security Settings. If not, create it.

  2. Inside it, create a boolean value called Allow Arbitrary Loads (if it's not there yet) and set it to YES.

App Transport Security Settings/Allow Arbitrary Loads with the value YES

Upvotes: 2

Related Questions