Ios Haneke未使用Swift使用AWS SDK
我正在尝试与AWS SDK集成,但图像没有显示Ios Haneke未使用Swift使用AWS SDK,ios,swift,amazon-web-services,amazon-s3,haneke,Ios,Swift,Amazon Web Services,Amazon S3,Haneke,我正在尝试与AWS SDK集成,但图像没有显示 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MyCollectionViewCell",
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
}
问题是您正在后台线程中更新UI。您应该将中的
.continueWithBlock{(task)->AnyObject!替换为。继续使用
中的xecutor(AWSExecutor.mainThreadExecutor(),使用block:{(task)->AnyObject!在主线程中运行该块
另外,如果您正在编写一个新的应用程序,我建议您使用AWSS3TransferUtility
而不是AWSS3TransferManager
,因为我们将把开发重点放在transfer实用程序上,并将逐步取消对transfer manager的支持。您能根据我的问题在这里显示完整的代码吗。