0

I am still new to KMM and need help on httpClient to ignore ssl certificate. I had made the request able to ignore ssl certificate by adding the following code to HTTPClient Android Engine:

HTTPClient(Android){
    engine{
        sslManager = {
                httpsURLConnection ->
            httpsURLConnection.hostnameVerifier = HostnameVerifier { _, _ -> true }
                httpsURLConnection.sslSocketFactory = sslContext.socketFactory
        }
    }
}

and on iOS Engine:

HTTPClient(Ios){
    engine{
        handleChallenge { session, task, challenge, completionHandler ->
                completionHandler(NSURLSessionAuthChallengeUseCredential, null)
        }
    }
}

However, I have an issue on iOS side. NSURLSessionAuthChallengeUseCredential despite inheriting from NSURLSessionAuthChallengeDisposition is a type of Kotlin.Long, but the completion handler’s first param only take NSURLSessionAuthChallengeDisposition which is a type of platform.darwin.NSInteger.

At first, i thought to just convert NSURLSessionAuthChallengeUseCredential to Int or platform.darwin.NSInteger. It didn’t triggered any error at android studio, but once i build it from xcode the following error pops up:

Type mismatch: inferred type is Int but NSURLSessionAuthChallengeDisposition /* = Long */ was expected

I think this is a bug because the xcode expect NSURLSessionAuthChallengeDisposition to be a long value, while kmm accept type of platform.darwin.NSInteger.

  • Have you tried building your code? It may be IDE bug, in this case the build should work fine. In any case, I suggest you [report it](https://youtrack.jetbrains.com/newIssue). – Phil Dukhov Mar 07 '22 at 00:08
  • I can't build it on Xcode. The build failed with the type mismatch error above. I will try reporting it. – Mocha Hilman Mar 07 '22 at 01:38
  • Try converting it to `Long`, as the error suggests – Phil Dukhov Mar 07 '22 at 02:38
  • I tried that too even though NSURLSessionAuthChallengeUseCredential supposed to be Long too, but the following error appear on the Android Studio side: "Type mismatch. Required: NSURLSessionAuthChallengeDisposition /* = Int */ Found: Long". The completionHandler doesn't accept Long, only NSURLSessionAuthChallengeDisposition which is a type of platform.darwin.NSInteger. – Mocha Hilman Mar 07 '22 at 03:32
  • This is the IDE bug I was talking about, if it builds fine, I suggest leaving it like this – Phil Dukhov Mar 07 '22 at 03:34
  • You're right! It builds just fine. Thanks for the help. – Mocha Hilman Mar 07 '22 at 03:50

0 Answers0