我正在创建自定义凭据提供程序,以便我可以设置accesskey,secretkey,token和expiration但是我在上传文件时收到以下错误 [__NSCFString expiration]:无法识别的选择器发送到实例
以下是我使用Swift 2.2创建的Custom类。请帮助我解决上述问题
_```
import AWSS3
import AWSCore.AWSCredentialsProvider
class MYAWSCredentialProvider:AWSCredentials, AWSCredentialsProvider{
var bucketName:String!
var token:String!
var awsAccessKey: String!
var awsSecretKey: String!
var awsExpiration: NSDate?
var awsRegion:String!
static let sharedInstance = MYAWSCredentialProvider(accessKey: "", secretKey: "", sessionKey: "")
@objc func logins() -> AWSTask {
return AWSTask(result: token)
}
init(accessKey: String, secretKey: String, sessionKey: String?) {
super.init()
self.token = sessionKey
self.awsAccessKey = accessKey
self.awsSecretKey = secretKey
}
private static func sharedInstanceWith(accessKey: String, secretKey: String, sessionKey: String) -> MYAWSCredentialProvider {
let instance = MYAWSCredentialProvider.sharedInstance
instance.token = sessionKey
instance.awsAccessKey = accessKey
instance.awsSecretKey = secretKey
return instance
}
func updateAWSInfo (jsonString: JSON) {
awsAccessKey = jsonString["accessKey"].stringValue
awsSecretKey = jsonString["secretKey"].stringValue
bucketName = jsonString["bucketName"].stringValue
awsRegion = jsonString["region"].stringValue
token = jsonString["token"].stringValue
let expirationTime = jsonString["expirationTime"].stringValue
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "E MMM d HH:mm:ss 'UTC' YYYY"////Fri Sep 30 14:42:53 UTC 2016
let date = dateFormatter.dateFromString(expirationTime)
awsExpiration = date
let credentialsProvider = MYAWSCredentialProvider.sharedInstanceWith(awsSecretKey, secretKey: awsSecretKey, sessionKey: token)
let configuration = AWSServiceConfiguration(region:AWSRegionType.APSoutheast1, credentialsProvider:credentialsProvider)
configuration.maxRetryCount = 3;
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
}
@objc func credentials() -> AWSTask {
return AWSTask(result: token)
}
func invalidateCachedTemporaryCredentials(){
}
}
答案 0 :(得分:1)
尝试用下面的替换你的功能。
@objc func credentials() -> AWSTask {
let credentials = AWSCredentials(accessKey: accessKey, secretKey: secretKey, sessionKey: sessionKey, expiration: nil)
return AWSTask(result: credentials)
}