I have followed some of tutorials from https://www.youtube.com/watch?v=UMgApUhg7ic to upload image to my s3 bucket.
This tutorial works perfectly fine with iOS simulator, but not working on my test iphone7. I have written some debug codes to figure out what is causing the problem, but none of it comes out.
I have searched for a while about this issue, but none of it mentioning my problem. Is there something that I am missing for my codes to work on actual device, not on simulator??
AppDelegate.swift
let AWS_Pool_ID = Bundle.main.object(forInfoDictionaryKey: "AWS_Pool_ID") as! String
let credentialsProvider = AWSCognitoCredentialsProvider(regionType:.APNortheast2, identityPoolId: AWS_Pool_ID)
let configuration = AWSServiceConfiguration(region:.APNortheast2, credentialsProvider:credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
UploadViewController.swift
let transferUtility = AWSS3TransferUtility.default()
let imageData = self.image.jpegData(compressionQuality: 1.0)
let imageName = UUID().uuidString+".jpg"
let bucketName = "hello-world-bucket-name"
let progressBlock:AWSS3TransferUtilityProgressBlock = { task,progess in
DispatchQueue.main.async {
progressView.progress = Float(progess.fractionCompleted)
}
}
let expression = AWSS3TransferUtilityUploadExpression()
expression.progressBlock = progressBlock
transferUtility.uploadData(imageData!, bucket: bucketName, key: imageName, contentType: "image/jpeg", expression: expression, completionHandler: { task,error in
print("transferutility works")
if let error = error {
print(error)
} else {
let imageURL = "https://\(bucketName).s3.ap-northeast-2.amazonaws.com/\(imageName)"
self.submitData.uploads = [imageURL]
print(URL(string:imageURL)!)
}
})