phantomon icon

Untitled

phantomon | PRO | 10/19/17 12:49:06 AM UTC | 0 ⭐ | 243 👁️ | Never ⏰ | []
Swift |

1.64 KB

|

None

|

0 👍

/

0 👎

//
//  ViewController.swift
//  SelfSignedSSL
//
//  Created by Edder Núñez on 10/18/17.
//  Copyright © 2017 Edder Núñez. All rights reserved.
//
 
import UIKit
 
class ViewController: UIViewController, URLSessionDelegate {
    
    var cert : URLCredential?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let session:URLSession = URLSession(configuration: URLSession.shared.configuration, delegate: self, delegateQueue: OperationQueue.main)
        let urlString:String = "https://chevrolet.map.smartcar.com/oauth/token"
        let url:URL = URL(string: urlString)!
        var request: URLRequest = URLRequest(url: url)
        session.dataTask(with: request) { (data, response, error) in
            print("cool 2")
            }.resume()
    }
    
    func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        print("cool 1")
        if let trust = challenge.protectionSpace.serverTrust {
            self.cert = URLCredential(trust: challenge.protectionSpace.serverTrust!)
            completionHandler(
                .useCredential,
                self.cert!
            )
        }else{
            completionHandler(
                .useCredential,
                self.cert!
            )
        }
        
    }
 
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
 
 
}

Comments