2017-07-16 74 views
1

我正在Google中登錄我的項目。我使用CocoaPods安裝了SDK。我有以前用Objective-C編寫的這個相同的應用程序。所以我從我的舊項目中拖動了相同的Google配置文件(GoogleService-Info.plist)。Google didSignInForUser不會迅速啓動3

而且我跟着this with CocoaPods installed method。但是當我按下登錄按鈕時,我正在指向Google網頁,輸入用戶名密碼後,它會返回到我的應用程序。但是這個代表沒有觸發。

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) { 
    if error == nil { 
     // Perform any operations on signed in user here. 
     let userId = user.userID     // For client-side use only! 
     let idToken = user.authentication.idToken // Safe to send to the server 
     let fullName = user.profile.name 
     let givenName = user.profile.givenName 
     let familyName = user.profile.familyName 
     let email = user.profile.email 
     let dm = Datamanager.sharedInstance 
     dm.gplusEmail = email 
     NotificationCenter.default.post(name: NSNotification.Name(rawValue: "RETURNED_GOOGLE"), object: nil) 
     // ... 
    } else { 
     print("\(error.localizedDescription)") 
    } 
} 

我在按鈕的標誌是一個UIButton,在我的ViewController我這樣已經實現:

@IBAction func googleClick(_ sender: UIButton) { 
    strLoggedWay="google" 
    GIDSignIn.sharedInstance().signIn() 
} 

請幫助我。我的代碼過程出了什麼問題?

回答

0
//In your login view controller 

@IBAction func googleClick(_ sender: UIButton) { 

    strLoggedWay="google" 

    GIDSignIn.sharedInstance().clientID = //getGoogleClientId 
    GIDSignIn.sharedInstance().serverClientID = //getGoogleServerClientId 
    GIDSignIn.sharedInstance().uiDelegate = self 
    GIDSignIn.sharedInstance().delegate = self 
    GIDSignIn.sharedInstance().scopes = @["https://www.googleapis.com/auth/userinfo.profile","https://www.googleapis.com/auth/userinfo.email"] 
    GIDSignIn.sharedInstance().signIn() 
} 

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, 
      withError error: NSError!) { 
    if (error == nil) { 
     // Perform any operations on signed in user here. 
     let userId = user.userID     // For client-side use only! 
     let idToken = user.authentication.idToken // Safe to send to the server 
     let fullName = user.profile.name 
     let givenName = user.profile.givenName 
     let familyName = user.profile.familyName 
     let email = user.profile.email 
     let dm=Datamanager.sharedInstance 
     dm.gplusEmail=email 
     NotificationCenter.default.post(name: NSNotification.Name(rawValue: "RETURNED_GOOGLE"), object: nil) 
     // ... 
    } else { 
     print("\(error.localizedDescription)") 
    } 
}