在我的 iOS 项目中,我需要实现 AWS SDK,就像我在该项目的 Android 版本中成功完成的那样,如果可能的话,使用 Swift Package Manager 而不是 Cocoapods。
由于 SPM 似乎尚不可用,因此我尝试了Soto,它允许我使用 SPM 实现 AWS 开发工具包。
这是我在我的 Android 项目中所做的,我想在 iOS 上复制:
- 我创建了一个
AWSInterface
接口,我所有的 api 端点都是:
@Service(endpoint = "https://abcde12345.execute-api.eu-central-1.amazonaws.com/dev")
interface AWSInterface
{
@Operation(path = "/api-demo", method = "POST")
fun apiDemo(
@Parameter(name = "Content-Type", location = "header") contentType: String,
body: ApiDemoModel): RetourStatutWS
}
- 这是
ApiDemoModel
非常简单的:
class ApiDemoModel(val code: String)
- 我创建了一个
AWSInterfaceHolder
类,所以我可以调用 api:
class AWSInterfaceHolder {
var awsInterface: AWSInterface = ApiClientFactory()
.credentialsProvider(AWSMobileClient.getInstance())
.clientConfiguration(ClientConfiguration().withConnectionTimeout(30000))
.build(AWSInterface::class.java)
}
- 我初始化
AWSMobileClient
,并调用我的 api:
AWSMobileClient.getInstance().initialize(
applicationContext,
object : Callback<UserStateDetails> {
override fun onResult(result: UserStateDetails?) {
// AWSMobileClient is successfully initialized, I can call my api:
val awsInterfaceHolder = AWSInterfaceHolder()
awsInterfaceHolder.awsInterface.apiDemo(
"application/json",
ApiDemoModel("123456"))
}
override fun onError(e: Exception?) {
e.printStackTrace()
}
}
如果可能的话,如何使用Soto为我的 iOS Swift 项目做同样的事情,因为默认的 AWS 开发工具包还不能用于 SPM?
谢谢。