我正在尝试与 AWS SDK 集成,但图像未显示。
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MyCollectionViewCell", forIndexPath: indexPath) as! MyCollectionViewCell
let downloadURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent("myImage.jpg")
let downloadRequest = AWSS3TransferManagerDownloadRequest()
downloadRequest.bucket = "stg"
downloadRequest.key = "myImage.jpg"
downloadRequest.downloadingFileURL = downloadURL
let transferManager = AWSS3TransferManager.defaultS3TransferManager()
transferManager.download(downloadRequest).continueWithBlock { (task) -> AnyObject! in
if task.error != nil {
print("Failed to download S3 with error \(task.error)")
}
if task.result != nil {
//let output = task.result as! AWSS3TransferManagerDownloadOutput
cell.imageView.contentMode = UIViewContentMode.ScaleAspectFit
cell.imageView?.hnk_setImageFromURL(downloadURL)
}
return nil
}
return cell
}