Heyy I am trying to make an API call using ktor us...
# multiplatform
j
Heyy I am trying to make an API call using ktor using the native engines, on ios I am getting an TLS sessions are not supported on Native platform error can anyone help me find a solution please? I am using ktor 1.6.0
r
I use this
Copy code
actual fun httpClient(config: HttpClientConfig<*>.() -> Unit) = HttpClient(Ios) {
    config(this)

    engine {
        configureRequest {
            setAllowsCellularAccess(true)
        }
    }
}
And it works fine
j
Thanks
@Rak when I implemented the function you sent me on my Ios app it sort of crashed Its not making the API call can you please send if thats possible the implementation in the Api class please?
r
which directory did you put that code?
What Api class?
j
In the iosMain
🙌 1
Where you are expecting this function and how u are using it in the common main directory
r
the expect is in commonMain
Copy code
expect fun httpClient(config: HttpClientConfig<*>.() -> Unit): HttpClient
and here’s my dependencies
Copy code
sourceSets {
        val commonMain by getting {
            dependencies {
                //Logger
                implementation("io.github.aakira:napier:1.5.0")

                // Ktor
                implementation("io.ktor:ktor-client-core:${properties["version.ktor"]}")
                implementation("io.ktor:ktor-client-logging:${properties["version.ktor"]}")
                implementation("io.ktor:ktor-client-serialization:${properties["version.ktor"]}")

                // Serialization
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.2.1")

                // SqlDelight
                implementation("com.squareup.sqldelight:runtime:${properties["version.sqldelight"]}")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("io.ktor:ktor-client-okhttp:${properties["version.ktor"]}")
                implementation("com.squareup.sqldelight:android-driver:${properties["version.sqldelight"]}")
            }
        }
        val iosMain by getting {
            dependencies {
                implementation("io.ktor:ktor-client-ios:${properties["version.ktor"]}")
                implementation("com.squareup.sqldelight:native-driver:${properties["version.sqldelight"]}")
            }
        }
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13.2")
            }
        }
        val iosTest by getting
    }
j
Yeah everything looks fine
Copy code
val apiCall = httpClient {  }
apiCall.get<HttpResponse>
this is my use case for it, its still causing the ios application to freeze when creating the client
r
what does your calling code look like?
213 Views