j

    Jad Doueik

    1 year ago
    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

    Rak

    1 year ago
    I use this
    actual fun httpClient(config: HttpClientConfig<*>.() -> Unit) = HttpClient(Ios) {
        config(this)
    
        engine {
            configureRequest {
                setAllowsCellularAccess(true)
            }
        }
    }
    And it works fine
    j

    Jad Doueik

    1 year ago
    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

    Rak

    1 year ago
    which directory did you put that code?
    What Api class?
    j

    Jad Doueik

    1 year ago
    In the iosMain
    Where you are expecting this function and how u are using it in the common main directory
    r

    Rak

    1 year ago
    the expect is in commonMain
    expect fun httpClient(config: HttpClientConfig<*>.() -> Unit): HttpClient
    and here’s my dependencies
    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

    Jad Doueik

    1 year ago
    Yeah everything looks fine
    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

    Rak

    1 year ago
    what does your calling code look like?