0

我是我大一经验少下一个新来的学生在夏季项目上工作,我得到的错误斯威夫特错误域= NSURLErrorDomain代码= -1012

错误域= NSURLErrorDomain代码= -1012“ (空)” 的UserInfo = {NSErrorFailingURLKey = https://localhost/donate/payment.php, NSErrorFailingURLStringKey = https://localhost/donate/payment.php}

,当我尝试运行通过磁条信用卡支付,我的代码是

func postStripeToken(token: STPToken) { 

    let URL = "https://localhost/donate/payment.php" 
    let params : [String: AnyObject] = ["stripeToken": token.tokenId, 
              "amount": myInt, 
              "currency": "usd", 
              "description": self.emailTextField.text!] 

    let manager = AFHTTPRequestOperationManager() 
    manager.POST(URL, parameters: params, success: { (operation, responseObject) -> Void in 

     if let response = responseObject as? [String: String] { 
      UIAlertView(title: response["status"], 
       message: response["message"], 
       delegate: nil, 
       cancelButtonTitle: "OK").show() 
     } 

    }) { (operation, error) -> Void in 
     self.handleError(error!) 
    } 
} 

它想要一个HTTP网址,而不是HTTPS但是当我将其更改为HTTP,当用户按下与他们的信用卡支付其未获得他们得到一个错误

资源无法加载海滩APP传输安全 策略需要使用安全连接。

是否有无论如何我可以使用HTTPS没有得到NSURL错误或我可以做一个安全的连接没有HTTPS?任何提示将非常有帮助!

manager.securityPolicy.allowInvalidCertificates = true; 

我也尝试添加这个声明没有运气。

回答

1

对于这一问题“The resource could not be loaded beach the APP Transport Security Policy requires the use of a secure connection”

只写下面的代码在你的info.plist

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