Hi team, hope you are doing well From the iOS nati...
# ktor
p
Hi team, hope you are doing well From the iOS native, I need to set delegate for NSURLSession. So is there any way to pass NSURLSession or NSURLSessionDelegate back to iOS? Any of your suggestions will make my day. Thanks. cc @Hien Nguyen
🙌 1
a
You can use the
usePreconfiguredSession
method inside the
engine
block. Here is an example:
Copy code
val client = HttpClient(Darwin) {
    val delegate = KtorNSURLSessionDelegate()
    val session = NSURLSession.sessionWithConfiguration(
        NSURLSessionConfiguration.defaultSessionConfiguration(),
        delegate,
        delegateQueue = NSOperationQueue()
    )
    engine {
        usePreconfiguredSession(session, delegate)
    }
}
p
Thanks @Aleksei Tirman [JB] Currently, we used ktor version
2.1.0
, also using
handleChallenge
AND
configureSession
in HttpClient(Darwin). Following by new version ktor https://api.ktor.io/ktor-client/ktor-client-darwin/io.ktor.client.engine.darwin/-darwin-client-engine-config/use-preconfigured-session.html
Copy code
"Set a session to be used to make HTTP requests. If the preconfigured session is set, configureSession and handleChallenge blocks will be ignored."
Do you have any suggestions? cc @Hien Nguyen @Trương Anh Ngoc
👍 1
hi @Aleksei Tirman [JB] We used CertificatePinner.Builder(), configureSession and handleChallenge for config http. Under your suggestion, using new NSURLSession and usePreconfiguredSession will ignore our previous config NSURLSession. Do you have any ideas please feel free to share. Thanks cc @Hien Nguyen @Trương Anh Ngoc
cc @Stoney
❤️ 1
cc @Hung Luong
❤️ 1
a
The problem is that the primary constructor of the
KtorNSURLSessionDelegate
is internal so there is no way to pass the
ChallengeHandler
to it.
Would it solve your problem if the constructor were public?
p
yup, the sound is good, then we can set KtorNSURLSessionDelegate from the out side, or we can have a new func like configureSession, something like that
Copy code
public fun configureSessionDelegate(block: NSURLSessionDelegate.() -> Unit)
How about your ideals @Aleksei Tirman [JB]? cc @Hien Nguyen @Trương Anh Ngoc @Hung Luong @Stoney
a
I don’t have a specific preference. Can you please file an issue then?
p
Please kindly refer to this issue. Thanks, so excited to see it available on version 2.2.4 https://youtrack.jetbrains.com/issue/KTOR-5688/KTORiOS-Support-access-NSURLSessionDelegate
a
I'll ask the assigned developer.
❤️ 1
101 Views