gpt4 book ai didi

swift - 自定义凭证提供程序问题 - Swift2.2、AWS 2.4.9、AWSCredentials AWSCredentialsProvider

转载 作者:行者123 更新时间:2023-11-28 16:09:14 25 4
gpt4 key购买 nike

我正在创建自定义凭证提供程序,以便我可以设置访问 key 、 key 、 token 和过期时间。但是我在上传文件时收到以下错误

[__NSCFString expiration]: unrecognized selector sent to instance

下面是我使用 Swift 2.2 创建的自定义类。我该如何解决这个问题?

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(){

}
}

最佳答案

尝试将您的函数替换为以下内容。

@objc func credentials() -> AWSTask {

let credentials = AWSCredentials(accessKey: accessKey, secretKey: secretKey, sessionKey: sessionKey, expiration: nil)

return AWSTask(result: credentials)

}

关于swift - 自定义凭证提供程序问题 - Swift2.2、AWS 2.4.9、AWSCredentials AWSCredentialsProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39795204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com