2017-09-28 43 views
0

我正在使用谷歌登錄Xamarin iOS應用程序,但是在顯示的Safari瀏覽器提示中成功輸入用戶名和密碼後,它將屬性CurrentUser返回爲null。谷歌登錄返回當前用戶爲空

我的代碼:

Google.SignIn.SignIn.SharedInstance.Delegate = this; 
Google.SignIn.SignIn.SharedInstance.UIDelegate = this; 
Google.SignIn.SignIn.SharedInstance.SignInUser(); 
Google.SignIn.SignIn.SharedInstance.SignedIn += SharedInstance_SignedIn; 

private void SharedInstance_SignedIn(object sender, SignInDelegateEventArgs e) 
{ 
var signin = (Google.SignIn.SignIn)sender; 
    //Here if i debug signin variable, its property CurrentUser comes as null 
} 

我使用 Xamarin.IOS.Google.Signin:v4.0.1.1

我失去了一些設置,需要在谷歌API控制檯啓用?

回答

1

Sender表示引發事件的類。

爲了得到用戶,您可以使用e.User或者Google.SignIn.SignIn.SharedInstance.CurrentUser

here explatins SignIn

在登錄SDK自動獲得訪問令牌,但訪問令牌將被刷新方法的功能只有在您調用SignIn或SignInSilently方法時纔有效。

+0

好吧,我得到CurrentUser,如果我添加Google.SignIn.SignIn.SharedInstance.SignInUser()觸發SharedInstance_SignedIn事件。 但如果我不添加Google.SignIn.SignIn.SharedInstance.SignInUser()它不會觸發事件 –

+0

@NathanN和你的問題? –

+0

是否需要激發SharedInstance_SignedIn事件的Google.SignIn.SignIn.SharedInstance.SignInUser()?在我的情況下,只有當我添加上面的行時纔會觸發事件 –