Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift&x2B;GIDSignIn-hasAuthInKeyChain返回true,但在显式调用后currentUser仍然为nil_Ios_Swift_Authentication_Keychain_Google Signin - Fatal编程技术网

Ios Swift&x2B;GIDSignIn-hasAuthInKeyChain返回true,但在显式调用后currentUser仍然为nil

Ios Swift&x2B;GIDSignIn-hasAuthInKeyChain返回true,但在显式调用后currentUser仍然为nil,ios,swift,authentication,keychain,google-signin,Ios,Swift,Authentication,Keychain,Google Signin,我正在尝试将Google登录集成到我的应用程序中。现在,我能够使用谷歌帐户成功登录用户,并且应用程序按预期工作-我能够访问currentUser,从中获取一些信息,并用这些信息填充我的应用程序视图。问题是,当我重新启动应用程序时,我无法获得一个GIDGoogleUser,即使是在显著地调用之后hasAuthInKeychain返回true,因此我知道密钥链中必须存在身份验证令牌。我就是不明白为什么currentUser在用户重新登录应用程序后仍然返回nil。我写的代码如下: guard

我正在尝试将Google登录集成到我的应用程序中。现在,我能够使用谷歌帐户成功登录用户,并且应用程序按预期工作-我能够访问
currentUser
,从中获取一些信息,并用这些信息填充我的应用程序视图。问题是,当我重新启动应用程序时,我无法获得一个
GIDGoogleUser
,即使是在显著地调用
之后
hasAuthInKeychain
返回true,因此我知道密钥链中必须存在身份验证令牌。我就是不明白为什么
currentUser
在用户重新登录应用程序后仍然返回nil。我写的代码如下:

    guard let signIn = GIDSignIn.sharedInstance() else { fatalError() }
    signIn.scopes = ["https://www.googleapis.com/auth/plus.stream.read", "https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/plus.login"]
    signIn.clientID = FIRApp.defaultApp()?.options.clientID
    signIn.delegate = self
    if signIn.hasAuthInKeychain() {
        signIn.signInSilently()
    }

    if signIn.hasAuthInKeychain() || FBSDKAccessToken.current() != nil {

        var token = String()
        if let user = signIn.currentUser{
            token = user.userID
        } else{
            token = FBSDKAccessToken.current().userID
        }
    }

由于
hasAuthInKeychain
返回true,应用程序尝试以静默方式登录。但是它跳过了
if let
语句,因为
currentUser
为nil,并直接尝试查找
FBSDKAccessToken
。我已经尝试了我找到的所有建议,包括设置登录范围。我错过什么了吗

我也有类似的问题。首先,我认为这是一个时间问题。在完全加载根viewController之后,通过调用signIn.signizenly(),它确实起了作用。我现在99%确定我通过在主线程上执行signIn.signizenly()解决了这个问题:

DispatchQueue.main.async {
    gidSignIn.signInSilently()
}

所以我实际上明白了我的问题所在。我在
中显著地调用了
,并用options
完成了启动,然后直接尝试检索
currentUser
currentUser
仅在委托方法(
didSignInForUser
)中填充,因此我需要在那里检索用户。