2017-03-21 30 views
1

嘗試使用AWSTransferutility通過Swift上傳照片時,出現此錯誤。模糊引用成員異步(執行:)我搜索了類似的問題,但沒有找到解決方案。在完成塊中對成員異步執行的模糊引用AWS S3 Swift 3

func uploadS3Background (dict: NSMutableDictionary) { 

    let transferUtility = AWSS3TransferUtility.default() 
    let expression = AWSS3TransferUtilityUploadExpression() 


    let completionHandler = { (task, error) -> Void in 

     DispatchQueue.main.async(execute: { 

     }) 
    } 

    transferUtility.uploadFile(URL(fileURLWithPath: dict.object(forKey: "url") as! String), 
    bucket: "bucketname/images", 
    key: (dict.object(forKey: "filename") as! String), 
    contentType: "image/png", 
    expression: expression, 
    completionHandler).continueWith { (task) -> AnyObject! in 

     if let error = task.error 
     { 
      print("Error: \(error.localizedDescription)") 
     } 

     if let _ = task.result 
     { 
      // Do something with uploadTask. 
     } 

     return nil; 
    } 
} 

在完成塊之外,我沒有在主隊列上分派錯誤。

enter image description here

回答

4

聲明此在您的視圖控制器 -

var completionHandler: AWSS3TransferUtilityUploadCompletionHandlerBlock? 

然後用

self.completionHandler = { (task, error) -> Void in 
      DispatchQueue.main.async(execute: { 

     }) 
} 
相關問題