Android Kotlin - 凭证管理器登录 - coroutineScope

问题描述 投票:0回答:1

我正在尝试实现新的登录方法,因为旧的登录方法已被弃用,但谷歌文档始终不完整。

这是我当前所在的部分:

coroutineScope.launch {
    try {
        val result = credentialManager.getCredential(
            request = request,
            context = this,
        )
        handleSignIn(result)
    } catch (e: GetCredentialException) {
        handleFailure(e)
    }
}

coroutineScope
是未解决的参考

我正在看这个教程: https://www.youtube.com/watch?v=P_jZMDmodG4

那里的那个人就这么做了:

val coroutineScope = rememberCoroutineScope()

这对他有用,但对我来说

rememberCoroutineScope()
也是未解决的参考

如何让它发挥作用?

提前致谢

android kotlin google-signin credential-manager
1个回答
0
投票

获取

CoroutineScope
的方法有多种,最常见的是在挂起函数中调用
coroutineScope { ... }
(或
withContext
及类似函数)或在
@Composable
函数中调用
rememberCoroutineScope()

后者似乎是您的示例中使用的。

© www.soinside.com 2019 - 2024. All rights reserved.