has anyone provided an instance of `NSURLSession` ...
# ktor
l
has anyone provided an instance of
NSURLSession
to ktor’s
HttpClient
? something like
Copy code
engine {
      val config = NSURLSessionConfiguration.defaultSessionConfiguration()
      val session = NSURLSession.sessionWithConfiguration(config)
      usePreconfiguredSession(session)
   }
It’s hard to debug the real issue but it basically does not work. The iOS app does not crash, but no network call is made.
a
I think you should add
Darwin
engine as a dependency in your iosMain you won't need to pass an engine as ktor will automatically detect it.
l
I am passing it, here’s the full class:
Copy code
actual class WikipediaHttpClientProvider @Inject constructor(
  client: NSURLSession,
  json: Json,
) {
  actual val value: WikipediaHttpClient = HttpClient(Darwin) {
    defaultRequest(getDefaultRequest())
    engine {
      usePreconfiguredSession(client)
    }
    install(ContentNegotiation) {
      json(json)
    }
  }
}
a
Okay. Can you share your build.gradle file especially the dependencies part
l
the relevant part:
Copy code
apply plugin: 'org.jetbrains.kotlin.multiplatform'

kotlin {
  iosX64()
  iosArm64()
  iosSimulatorArm64()
  sourceSets {
  iosMain {
      dependsOn commonMain
      dependencies {
        api 'io.ktor:ktor-client-darwin:2.1.2'
      }
      iosX64Main.dependsOn it
      iosArm64Main.dependsOn it
      iosSimulatorArm64Main.dependsOn it
    }
}
a
Okay you have Darwin as dep. In your
commonMain
don't need pass in an engine. Just calling
HttpClient()
will automatically pick the engine for different platforms as long as the engine dependency is in the classpath. So basically you don't have actual/expect the client yourself.
l
Yeah I figured that too, but I need to pass a customized NSURLSession instead of letting Ktor build independently
r
Indeed, this API is broken. Please create a ticket in YouTrack
l
Thanks for confirming, Rustam. I’d love to add more details, but I quite don’t get much from the error and/or logs. But let me know how more I can help 🙏 https://youtrack.jetbrains.com/issue/KTOR-5134
r
I know what’s happening there. Will try to fix it in next release
l
Thank you 🙏 🙏