Search code examples
swiftuiwebviewios9cfnetworksslhandshakeexception

CFNetwork SSLHandshake failed (-9824) Loading URL in UIWebView


All posts & tutorials which i accessed, gives the solution to edit the info.plist file, & i did the same.

Editing plist file works for google.co.in But does not work for https://www.onlinesbi.com

I just want to know my mistake Please guide.

My info.plist

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
     "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
        <dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>com.abcd.abcdAppstore.$(PRODUCT_NAME:rfc1034identifier)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>BNDL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>www.onlinesbi.com</key>
            <dict>
                <key>NSTemporaryExceptionRequiresForwardSecrecy</key> <false/>
                <!--Include to allow subdomains-->
                <key>NSIncludesSubdomains</key>
                <true/>
                <!--Include to allow insecure HTTP requests-->
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <!--Include to specify minimum TLS version-->
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.2</string>
            </dict>
        </dict>
    </dict>
    </dict>
</plist>

My ViewController

    private var URL = "https://www.onlinesbi.com"
override func viewDidLoad() {
        super.viewDidLoad()
let url = NSURL (string: URL);
            let requestObj = NSURLRequest(URL: url!);
            myWebview.loadRequest(requestObj);
}//viewDidLoad closes here....

EDIT

I tried updating my info.plist to :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>com.abcd.abcdAppstore.$(PRODUCT_NAME:rfc1034identifier)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>BNDL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>onlinesbi.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <true/>
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.2</string>
                <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
                <false/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <true/>
                <key>NSThirdPartyExceptionMinimumTLSVersion</key>
                <string>TLSv1.2</string>
                <key>NSRequiresCertificateTransparency</key>
                <false/>
            </dict>
        </dict>
    </dict>
</dict>
</plist>

But still the web view is empty. :-(

Also i tried to edit the Developer option of my Simulator but didn't succeed.

Any help will be appreciated. Thanks in advance


Solution

  • Finally got the answer as:

    1. I had started my code on Xcode 6.x & iOS version 7.x, but after some time i upgraded my Xcode to Xcode 7.x & iOS version 9.x. So the Xcode automatically did some changes. In these automatic changes, something wrong happened & UIWebview started working weird.

    2. How did i conclude at above point ?? Ans: I made a new project on Xcode 7.x & iOS 9.x then the code was running correctly.

    3. What is the final info.plist?


    As matinict suggested,

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

    worked for me.

    Just i kept it at the end & not at the start.