【问题标题】:Haneke not working with AWS SDK using SwiftHaneke 不使用 Swift 与 AWS 开发工具包一起工作
【发布时间】:2015-11-18 08:22:20
【问题描述】:

我正在尝试与 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
    }

【问题讨论】:

    标签: ios swift amazon-web-services amazon-s3 haneke


    【解决方案1】:

    问题是您正在后台线程中更新 UI。您应该将 .continueWithBlock { (task) -> AnyObject! in 替换为 .continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (task) -> AnyObject! in 以在主线程中运行该块。

    另外,如果您正在编写新应用,我建议您使用 AWSS3TransferUtility 而不是 AWSS3TransferManager,因为我们将把开发工作重点放在传输实用程序上,并将逐步停止对传输管理器的支持。

    【讨论】:

    • 你能根据我的问题在这里显示完整的代码吗?
    猜你喜欢
    • 2016-12-15
    • 2022-10-24
    • 2012-09-21
    • 2018-01-19
    • 2021-07-08
    • 1970-01-01
    • 1970-01-01
    • 2019-11-04
    • 1970-01-01
    相关资源
    最近更新 更多