simplesystems
simplesystems

Reputation: 849

Call iOS webview HTTPS (self-signed certificate)

I want to call HTTPS url (self-signed certificate) in my iOS App. it works on the mobile browser but not in the App Webview.

Is there a solution for Xcode 7 and Swift 2.2?

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let url = NSURL(string: "https://xxx.xxx.x.xxx:xxxx")

        let request = NSURLRequest(URL: url!)
        Webview.loadRequest(request)
    }

Upvotes: 0

Views: 1744

Answers (2)

Durai Amuthan.H
Durai Amuthan.H

Reputation: 32270

You have to install the Self Signed Certificate or CA on the device in order for the device to trust it then only device trusts the SSL connection.

In the case of installing self signed certificate make sure domain name of the URL is same as Common name of certificate.

If there is no domain name then IP address is fine.

Certificate installation:

You can just host it on the web server and try to access it from safari then iOS will prompt for the certificate installation in the iOS Device

Certificate Creation:

Here is the way to create self signed certificate so that you can fill all the details and host in web server.

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 1001 -nodes

(Pay attention while entering the value for Common Name)

Upvotes: 7

Bandish Dave
Bandish Dave

Reputation: 811

try to add below code in your plist file.

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

Upvotes: -1

Related Questions