1

I'm using the AWS iOS SDK to upload files to S3. I am using AWSS3TransferUtility because I want to allow background uploads.

The background task is working - a large file can successfully upload while backgrounded. The issue is, when I bring my app back to the foreground, the task.result.progress.fractionCompleted value remains at the value from before being backgrounded. And if I foreground my app before the upload is complete, the progress value will remain at that value until it is done, then jump up to 1.0.

When the app comes back to the foreground, I call enumerateToAssignBlocksForUploadTask:multiPartUploadBlocksAssigner:downloadBlocksAssigner: on my TransferUtility class, and I reassign the progress and completion handlers.

Does anyone know what may cause that value not to update? I'm not sure how to resume updating my progress bar because of this. Thanks!

Edit: Here is where I start the upload process. I have a wrapper around the AWS Task that holds onto the progress and completion handlers.

func upload(storagePath: String, sourceURL: URL, _ progressCompletion: @escaping ProgressCompletionCallback)-> UploadTask {

    let expression = AWSS3TransferUtilityMultiPartUploadExpression()
    expression.progressBlock = {(task, progress) in
        DispatchQueue.main.async(execute: {
            print("Progess: \(progress)")
            progressCompletion(false, Float(progress.fractionCompleted), nil)
        })
    }

    var completionHandler: AWSS3TransferUtilityMultiPartUploadCompletionHandlerBlock
    completionHandler = { (task, error) -> Void in
        DispatchQueue.main.async(execute: {
            print("Completed!")
            progressCompletion(true, Float(task.progress.fractionCompleted), error)
        })
    }

    let awsTask = transferUtility.uploadUsingMultiPart(fileURL: sourceURL,
                                         bucket: Constants.bucketName,
                                         key: storagePath,
                                         contentType: "text/plain",
                                         expression: expression,
                                         completionHandler: completionHandler)

    return UploadTask(task: awsTask,
                      progressBlock: expression.progressBlock!,
                      completionBlock: completionHandler)

}
Jake G
  • 1,185
  • 9
  • 19

1 Answers1

0

I am facing the same issue when downloading files. Here is a link to the issue i opened on their github page, atleast for the case of downloading files. They don't receive callbacks from the NSURLSession class thats being used. It is probably something similar in your case.

Rikh
  • 4,078
  • 3
  • 15
  • 35
  • I am facing the same issue as "Jake G" mentioned, but I am not using AWS. Any solution to get the progress of the background download task? – Peer Mohamed Thabib Jun 17 '19 at 09:00
  • another observation, the progress working in Xcode simulator for the background downloads when we bring the app from background to foreground. The issue is only with the real device. – Peer Mohamed Thabib Jun 17 '19 at 10:11