KMM iOS HttpClient NSURLSessionAuthChallengeDisposition 类型错误问题

发布于 2025-01-11 22:24:01 字数 1239 浏览 1 评论 0原文

我对 KMM 还很陌生,需要有关 httpClient 的帮助来忽略 ssl 证书。 使请求能够忽略 ssl 证书

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

我通过将以下代码添加到 HTTPClient Android Engine:和 iOS Engine: 上,

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

:但是,我在 iOS 端遇到了问题。 NSURLSessionAuthChallengeUseCredential 尽管继承自 NSURLSessionAuthChallengeDisposition 是一种 Kotlin.Long,但完成处理程序的第一个参数仅采用 NSURLSessionAuthChallengeDisposition,它是一种 platform.darwin.NSInteger 类型。

起初,我想将 NSURLSessionAuthChallengeUseCredential 转换为 Int 或 platform.darwin.NSInteger。它没有在 android studio 中触发任何错误,但是一旦我从 xcode 构建它,就会弹出以下错误:

类型不匹配:推断类型是 Int,但是 NSURLSessionAuthChallengeDisposition /* = Long */ 是预期的

我认为这是一个错误,因为 xcode 期望 NSURLSessionAuthChallengeDisposition 为 long 值,而 kmm 接受 platform.darwin.NSInteger 类型。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文