2015-11-12 125 views
2

我已經配置Google SDK for ios使用pods.and我添加了一個uiview作爲登錄按鈕(設置類爲GIDSignInButton)。並添加了連接。但是當我按下按鈕時,它不會顯示任何東西。它不調用委託方法。我在網上搜索,但沒有發現。請指導我解決這個問題。當按谷歌登錄按鈕時什麼也沒有發生

謝謝

這裏是我的viewControllar

class Login: UIViewController , GIDSignInUIDelegate{ 

@IBOutlet var googleLogIn: GIDSignInButton! 
override func viewDidLoad() { 
    super.viewDidLoad() 

    GIDSignIn.sharedInstance().uiDelegate = self 

    // Uncomment to automatically sign in the user. 
    // GIDSignIn.sharedInstance().signInSilently() 

    // TODO(developer) Configure the sign-in button look/feel 
    // ... 
} 
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 name = user.profile.name 
      let email = user.profile.email 
      // ... 
     } else { 
      print("\(error.localizedDescription)") 
     } 
} 

func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!, 
    withError error: NSError!) { 
     // Perform any operations when the user disconnects from app here. 
     // ... 
} 

這裏是我的應用程序委託

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    // Override point for customization after application launch. 


    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 
    //Optionally add to ensure your credentials are valid: 

    var configureError: NSError? 
    GGLContext.sharedInstance().configureWithError(&configureError) 
    assert(configureError == nil, "Error configuring Google services: \(configureError)") 

    GIDSignIn.sharedInstance().delegate = self 


    return true 
} 


func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { 
    return GIDSignIn.sharedInstance().handleURL(url, 
     sourceApplication: sourceApplication, 
     annotation: annotation) 
    //FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) 
} 

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 name = user.profile.name 
      let email = user.profile.email 
      // [START_EXCLUDE] 
      NSNotificationCenter.defaultCenter().postNotificationName(
       "ToggleAuthUINotification", 
       object: nil, 
       userInfo: ["statusText": "Signed in user:\n\(name)"]) 
      // [END_EXCLUDE] 
     } else { 
      print("\(error.localizedDescription)") 
      // [START_EXCLUDE silent] 
      NSNotificationCenter.defaultCenter().postNotificationName(
       "ToggleAuthUINotification", object: nil, userInfo: nil) 
      // [END_EXCLUDE] 
     } 
} 

func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!, 
    withError error: NSError!) { 
     // Perform any operations when the user disconnects from app here. 
     // [START_EXCLUDE] 
     NSNotificationCenter.defaultCenter().postNotificationName(
      "ToggleAuthUINotification", 
      object: nil, 
      userInfo: ["statusText": "User has disconnected."]) 
     // [END_EXCLUDE] 
} 

回答

1

驗證,一旦你加入你在你的應用程序clientID

func application(application: UIApplication, 
    didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
GIDSignIn.sharedInstance().clientID = "XXXXX-XXXXX.apps.googleusercontent.com"; 

return true 
} 

appdelegate刪除行GIDSignIn.sharedInstance().delegate = self並添加視圖控制器,試一次

GIDSignIn.sharedInstance().delegate = self 
    GIDSignIn.sharedInstance().uiDelegate = self 
+0

關於客戶端ID;他們從未提及要包含客戶端ID。 thay必須從info.plist中取出。但我會嘗試這 –

+0

@GishanthaJayasooriya - 嘗試一次,如果你沒有在這裏得到答案的答覆,我會支持你http://www.riskcompletefailure.com/2015/03/google-sign-in-ios-100.html –

+0

我曾嘗試給客戶端ID。但我不能分配GIDSignIn.sharedInstance()。委託=自我因爲我在我的uiviewControllar中使用GIDSignInUIDelegate。我現在能做什麼 –

5

,如果其他人正面臨着這個問題,我不知道。我知道這可能不是你的情況,但對於其他人,我也面臨同樣的問題,但在我的情況下,我在容器視圖中添加了Google Sign in按鈕,其中有Tap Gesture,用於解開鍵盤,因爲當我點擊Google Sign在中,它並沒有用於工作。 只是從我的一端有點愚蠢:)

+0

對不起,我不明白你的建議這裏。你是說我們應該把GIDSignInButton放在容器視圖中?最重要的是什麼?我也有同樣的問題,SFSafariViewController沒有被解僱,它只是回落到www.google.com,而不是解僱和回到我的應用程序界面。 – omarojo

+0

哇,你讓我的一天 – Shrolox

+0

@Shrolox高興我可以幫到 –

相關問題