In my iOS project, I need to implement the AWS SDK, as I successfully did in the Android version of that project, if possible using Swift Package Manager and not Cocoapods.
Since it doesn't seem to be available yet for SPM, I tried Soto, that allows me to implement the AWS SDK using SPM.
Here is what I did in my Android project, that I want to replicate on iOS:
- I created an
AWSInterface
interface, where all my api endpoints are:
@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
}
- and here is the
ApiDemoModel
, very simple:
class ApiDemoModel(val code: String)
- I created an
AWSInterfaceHolder
class, so I'll be able to call apis:
class AWSInterfaceHolder {
var awsInterface: AWSInterface = ApiClientFactory()
.credentialsProvider(AWSMobileClient.getInstance())
.clientConfiguration(ClientConfiguration().withConnectionTimeout(30000))
.build(AWSInterface::class.java)
}
- I initialized
AWSMobileClient
, and call my 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()
}
}
How can I do the same for my iOS Swift project, if possible using Soto, since the default AWS SDK is not available for SPM yet?
Thanks.