2017-01-10 25 views
0

我使用下面的共享實例創建一個會話管理器:AlamoFire:公鑰穿針不工作

class Session { 
static let sharedInstance = Session() 

private var manager : SessionManager? 

func ApiManager()->SessionManager{ 
    if let m = self.manager{ 
     return m 
    }else{ 

     let serverTrustPolicies: [String: ServerTrustPolicy] = [ 
      "https:api-cat.example.com": .pinPublicKeys(
       publicKeys:savePublicKeys(), 
       validateCertificateChain:true, 
       validateHost:true 
      )] 
     self.manager = SessionManager(
      serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)) 
     return self.manager! 
    } 
}} 

其中savePublicKeys回報[SecKey]

即使在使用空的公鑰數組設置新的ServerTrustPolicy後,我仍然能夠成功調用並獲取數據。 任何想法,如果我在這裏犯任何錯誤?

回答

1

"https:api-cat.payeezy.com"看起來腥。

要麼刪除https:雙組分或添加缺少的雙斜線https://ServerTrustPolicyManager僅在其主機屬性與請求的主機匹配時才應用策略,如果這些策略不匹配,則使用Apple的標準行爲(請參閱Alamofire Documentation)。

+0

這解決了我的問題。感謝ChaosCoder。只是想添加這個,但問題是在'https'後缺少'//'。你可以改變你的答案以反映相同的情況。 – SagarU