2017-01-11 12 views
12

Używam metody przesyłania treści do przesłania pliku w trybie AWSLocal. Muszę anulować przesyłanie z innego ekranu.Zatrzymaj/Anuluj Przesyłanie na AWS S3

Oto funkcja przesyłania:

private func uploadLocalContent(localContent: AWSLocalContent) { 
    localContent.uploadWithPinOnCompletion(false, progressBlock: {[weak self](content: AWSLocalContent?, progress: NSProgress?) -> Void in 
     guard let strongSelf = self else { return } 
     dispatch_async(dispatch_get_main_queue()) { 
      // Update the upload UI if it is a new upload and the table is not yet updated 
      if(strongSelf.tableView.numberOfRowsInSection(0) == 0 || strongSelf.tableView.numberOfRowsInSection(0) < strongSelf.manager.uploadingContents.count) { 
       strongSelf.updateUploadUI() 
      } else { 

       for uploadContent in strongSelf.manager.uploadingContents { 
        if uploadContent.key == content?.key { 
         let index = strongSelf.manager.uploadingContents.indexOf(uploadContent)! 
         let indexPath = NSIndexPath(forRow: index, inSection: 0) 
         strongSelf.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .None) 
        } 
       } 
      } 
     } 
     }, completionHandler: {[weak self](content: AWSContent?, error: NSError?) -> Void in 
      guard let strongSelf = self else { return } 
      strongSelf.updateUploadUI() 
      if let error = error { 
       print("Failed to upload an object. \(error)") 
       strongSelf.showSimpleAlertWithTitle("Error", message: "Failed to upload an object.", cancelButtonTitle: "OK") 
      } else { 
       strongSelf.refreshContents() 
      } 
     }) 
    updateUploadUI() 
} 
+0

Czy __need__ anulować lub wywołuje removeRemoteContentWithCompletionHandler po przesłaniu i nie robi to, co jest w hander zakończeniu wystarczy? –

Odpowiedz

1

Niestety nie ma sposobu, aby anulować przesyłanie, gdy wywołana z AWSLocalContent jak nie ma dostępu do AWTask.

Look w AWSS3TransferManager (http://docs.aws.amazon.com/AWSiOSSDK/latest/Classes/AWSS3TransferManager.html#//api/name/upload :), który tworzy AWTask dla każdego działania, można je przesłać lub do pobrania, które mogą być anulowane/wstrzymane/wznowione. Dodatkowo otrzymujesz metody wygody od AWSS3TransferManager, które mogą anulować/wstrzymać/wznowić wszystkie zadania naraz.

Musisz utworzyć przesyłający AWTask, zachować go w miejscu dostępnym z drugiego ekranu, a następnie możesz go anulować.

Powiązane problemy