我有一个swift
项目,我在那里使用亚马逊网络服务。
我有一个函数负责将图像上传到我的S3
存储桶,在Swift 2.2中它运行良好,代码如下:
let credentialsProvider = AWSCognitoCredentialsProvider(regionType:CognitoRegionType,
identityPoolId:CognitoIdentityPoolId)
let configuration = AWSServiceConfiguration(region:CognitoRegionType, credentialsProvider:credentialsProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
let uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest.body = NSURL(string: "file://"+pathToFile)
uploadRequest.key = NSProcessInfo.processInfo().globallyUniqueString + "." + ext
uploadRequest.bucket = S3BucketName
uploadRequest.contentType = contentType + ext
let transferManager = AWSS3TransferManager.defaultS3TransferManager()
transferManager.upload(uploadRequest).continueWithBlock { (task) -> AnyObject! in
if (task.completed) {
...
现在,升级到Swift 3后,我有:
let credentialsProvider = AWSCognitoCredentialsProvider(regionType:CognitoRegionType,
identityPoolId:CognitoIdentityPoolId)
let configuration = AWSServiceConfiguration(region:CognitoRegionType, credentialsProvider:credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
let uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest?.body = URL(string: "file://"+pathToFile)
uploadRequest?.key = ProcessInfo.processInfo.globallyUniqueString + "." + ext
uploadRequest?.bucket = S3BucketName
uploadRequest?.contentType = contentType + ext
let transferManager = AWSS3TransferManager.default()
transferManager?.upload(uploadRequest).continueWithBlock { (task) -> AnyObject! in
if (task.isCompleted) {
现在在最后一个语句中transferManager?.upload(uploadRequest).continueWithBlock
会抛出一个错误
'continueWithBlock' has been renamed to 'continue(_:)'
所以我按照他们的建议将其改为:
transferManager?.upload(uploadRequest).continue {
然后它给我一个错误:
Ambigous use of continue
可用的方法在这里:
但我不确定在这种情况下我可以使用哪一个。你能帮帮我吗?
答案 0 :(得分:4)
好的我发现了这个问题,它比我想象的要容易......这里提到过:https://github.com/aws/aws-sdk-ios/issues/473并说要改变
transferManager?.upload(uploadRequest).continue { ... }
到
transferManager?.upload(uploadRequest).continue ({ ... })
在这种情况下,方法命名确实很烦人,但它确实有效。