코드를 Swift 3으로 업데이트했으며 Alamofire 4.0으로의 마이그레이션에 문제가 있습니다. 필자는 Alamofire 마이그레이션 가이드를 사용하여 필요한 수정 작업을 성공적으로 수행했지만 이미지 데이터를 가져 오는 데는 여전히 문제가 있습니다. (의도 한대로 일)Alamofire 요청으로 이미지 데이터 가져 오기
오래된 스위프트 2/Alamofire 3 코드 : Alamofire 4 으로 업데이트에서
func beginGetImageRequest() {
if let imagePath = thumbPath {
request = Alamofire.request(.GET, imagePath).response(completionHandler: { (_, _, imageData, error) -> Void in
if error != nil {
NSLog("Error downloading thumbnail image: \(error)")
} else {
if let downloadedImage = UIImage(data: imageData!) {
self.imageView.image = downloadedImage
}
}
})
}
}
내 시도 :
func beginGetImageRequest() {
if let imagePath = thumbPath {
request = Alamofire.request(imagePath, method: .get, parameters: [:], encoding: JSONEncoding.default)
.validate { request, response, imageData in
if let downloadedImage = UIImage(data: imageData!) {
self.imageView.image = downloadedImage
} else {
print(response)
print(imageData)
}
return .success
}
}
}
print(imageData)
출력 Optional(306 bytes)
. 이미지는 UIImage로 데이터를 변환하는 방법이 아니라 요청을 구현하는 방법에 문제가 있음을 알려주는 약 40KB 여야합니다. 여기
print(response)
<NSHTTPURLResponse: 0x618000221660> { URL: http://209.126.98.238/cache/igames_thumb/images/games/53848027743af.jpeg } { status code: 400, headers {
Connection = close;
"Content-Encoding" = gzip;
"Content-Length" = 245;
2016-10-04 21:54:53.653480 EyeGames[74216:3416747] [] nw_connection_send_stats_report 21 Generated report:
Delegated: 0
Report reason: app data stall
TCP statistics report:
Time to DNS start: 0 ms
Time to DNS resolved: 0 ms
DNS resolved time: 0 ms
DNS answers cached: 0
Interface type: 1
Time to TCP start: 3 ms
Time to TCP establishment: 223 ms
Connection establishment: 220 ms
Flow duration: 11447 ms
Connected interface type: 1
Connected: 1
Traffic class: 0
Cellular fallback: 0
Cellular RRC connected: 0
Kernel reported stalls: 0
Kernel reported connection stalls: 0
Kernel reported read stalls: 0
Kernel reported write stalls:
"Content-Type" = "text/html; charset=iso-8859-1";
Date = "Tue, 04 Oct 2016 18:54:43 GMT";
Server = "Apache/2.2.22 (Debian)";
Vary = "Accept-Encoding";
} }
Alamofire.request
그리고 무엇 응답이 포함를 호출하기 전에 URL에 대한 캐시를 제거 할 수 있습니까? 당신은 거기에서 시작해야합니다 – Godfather@ Godfather 응답에서 출력을 포함하도록 내 질문을 편집했습니다 –
당신은 400 오류 코드를 받고 있습니다. 요청이 잘못되었습니다. 인코딩을 URL로 변경해보십시오 – Godfather