Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Haneke未使用Swift使用AWS SDK_Ios_Swift_Amazon Web Services_Amazon S3_Haneke - Fatal编程技术网

Ios Haneke未使用Swift使用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",

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

问题是您正在后台线程中更新UI。您应该将中的
.continueWithBlock{(task)->AnyObject!替换为
。继续使用
中的xecutor(AWSExecutor.mainThreadExecutor(),使用block:{(task)->AnyObject!在主线程中运行该块


另外,如果您正在编写一个新的应用程序,我建议您使用
AWSS3TransferUtility
而不是
AWSS3TransferManager
,因为我们将把开发重点放在transfer实用程序上,并将逐步取消对transfer manager的支持。

您能根据我的问题在这里显示完整的代码吗。