2017-01-11 6 views
1

에서 사진을 가져 오기 위해있는 NSData를 사용하는 방법이 내 코드입니다. 네트워크 요청을하면 연결할 URL은 https://localhost:8443/news/p0.jpg입니다.스위프트

2017년 1월 11일 : 10 : 11 : 28.888 직업이 오류 얻을 [19800을 : 2397129] NSURLSession /있는 NSURLConnection HTTP로드 (kCFStreamErrorDomainSSL, -9813) 오류

실패하지만이왔다 Alamofire를 사용하여 다른 장소에서 https에 연결하는 것은 매우 성공적이었습니다. 그게 뭐가 잘못 되었 니?

OK, 나는 URLData을 사용하려고하지만이

+2

Swift를 사용 중입니다. 'NSData' 또는'NSURL'을 사용하지 마십시오. 'Data'와'URL'을 사용하십시오. – rmaddy

+0

해당 URL에 문제가없는 것은 확실합니다. 방금 브라우저에서 붙여 넣기를 시도했지만 오류가 발생했습니다. – Pierce

+0

"localhost"에 연결되었습니다. 그게 당신이 응용 프로그램을 실행하는 장치 (시뮬레이터의 경우 Mac, 실제 장치에서 테스트하는 경우 iOS 장치)입니다. 시뮬레이터를 사용한다고 가정 할 때 Mac에 포트 8443에서 실행되는 웹 서버에 유효한 SSL 인증서가 있습니까? 물론 – rmaddy

답변

0

OK, 그것은 완료 오류와 아무 상관이있다! 연결을 관리하는 데 Alamofire을 사용하기 때문에 alamofire를 사용하여 이미지 데이터를 가져와야합니다. 원래의 방법보다 !!

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "news", for: indexPath) 
    let lebel = cell.viewWithTag(1) as! UILabel 
    let lebel1 = cell.viewWithTag(2) as! UILabel 
    let pict = cell.viewWithTag(3) as! UIImageView 
    lebel.text = self.titlename[indexPath.row] 
    lebel1.text = self.content[indexPath.row] 
    if let imageURL = URL(string:self.picture[indexPath.row]) { 
     Alamofire.request(imageURL, method: .get).responseData { response in 
      guard let data = response.result.value else { 
       pict.image = nil 
       //cell.imageView?.image = UIImage(named: "failed") 
       return 
      } 
      pict.image = UIImage(data: data) 
     } 
    } 
    return cell 
} 

하지만 너무 고마워!