I am using the AWS SDK for iOS in a swift application for iOS 12. My app has to list files in a AWS S3 bucket and download some of them. The list files operation works well and I succeeded in having control of its timeout. I did not succeed to do that for the download task. My code is the following:
let credentialProvider = AWSCognitoCredentialsProvider(regionType: AWSRegionType.USEast1, identityPoolId: "<pool-id>")
let configuration = AWSServiceConfiguration(region: AWSRegionType.APSoutheast2, credentialsProvider: credentialProvider)
configuration?.timeoutIntervalForRequest = 30.0
configuration?.timeoutIntervalForResource = 86400
let transferUtilityConfiguration = AWSS3TransferUtilityConfiguration.init()
transferUtilityConfiguration.timeoutIntervalForResource = 86400
transferUtilityConfiguration.retryLimit = 1
AWSS3TransferUtility.register(with: configuration!, transferUtilityConfiguration: transferUtilityConfiguration, forKey: "com.mykey")
transferUtility = AWSS3TransferUtility.s3TransferUtility(forKey: "com.mykey")
let bucket = "com.mybucket"
transferUtility.configuration.maxRetryCount = 1
let urlForSavingFile = URL.init(fileURLWithPath: "")
transferUtility.download(to: urlForSavingFile, bucket: bucket, key: self.latestFileOnServer.key, expression: expression, completionHandler: self.completionHandler).continueWith { (task) -> AnyObject? in
if let error = task.error {
NSLog("Error: %@",error.localizedDescription);
DispatchQueue.main.async(execute: {
statusLabel.text = "Failed"
})
}
if let _ = task.result {
self.refDownloadTask = task.result
self.refDownloadTask?.setCompletionHandler(self.completionHandler!)
methodStart = Date.init()
let formatter = DateFormatter.init()
formatter.dateFormat = "dd' 'MMM' 'YYYY' - 'HH:mm:ss"
formatter.locale = Locale.init(identifier: "Europe / Rome")
let italyDate = formatter.string(from: methodStart)
print("Download started at \(italyDate)")
DispatchQueue.main.async(execute: {
//statusLabel.text = "Downloading..."
})
NSLog("Download Starting!")
// Do something with uploadTask.
}
return nil;
}
The completion handler is properly called if I wait for the file to finish downloading, but if I turn off the network with the network link conditioner the transfer hangs forever and the completion handler is never called. Any help is much appreciated. Thanks