phantomon

Untitled

Oct 18th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.64 KB | None | 0 0
  1. //
  2. //  ViewController.swift
  3. //  SelfSignedSSL
  4. //
  5. //  Created by Edder Núñez on 10/18/17.
  6. //  Copyright © 2017 Edder Núñez. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class ViewController: UIViewController, URLSessionDelegate {
  12.    
  13.     var cert : URLCredential?
  14.    
  15.     override func viewDidLoad() {
  16.         super.viewDidLoad()
  17.         // Do any additional setup after loading the view, typically from a nib.
  18.         let session:URLSession = URLSession(configuration: URLSession.shared.configuration, delegate: self, delegateQueue: OperationQueue.main)
  19.         let urlString:String = "https://chevrolet.map.smartcar.com/oauth/token"
  20.         let url:URL = URL(string: urlString)!
  21.         var request: URLRequest = URLRequest(url: url)
  22.         session.dataTask(with: request) { (data, response, error) in
  23.             print("cool 2")
  24.             }.resume()
  25.     }
  26.    
  27.     func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
  28.         print("cool 1")
  29.         if let trust = challenge.protectionSpace.serverTrust {
  30.             self.cert = URLCredential(trust: challenge.protectionSpace.serverTrust!)
  31.             completionHandler(
  32.                 .useCredential,
  33.                 self.cert!
  34.             )
  35.         }else{
  36.             completionHandler(
  37.                 .useCredential,
  38.                 self.cert!
  39.             )
  40.         }
  41.        
  42.     }
  43.  
  44.     override func didReceiveMemoryWarning() {
  45.         super.didReceiveMemoryWarning()
  46.         // Dispose of any resources that can be recreated.
  47.     }
  48.  
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment