按google登录按钮时没有任何反应

时间:2015-11-12 07:28:57

标签: ios iphone google-plus swift2 google-signin

我已经使用pods为ios配置了Google SDK。我添加了一个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.
        // ...
}

这是我的app delegate

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]
}

3 个答案:

答案 0 :(得分:5)

我不知道是否有其他人正面临这个问题。我知道这可能不是你的情况,但对于其他任何人我也面临同样的问题,但在我的情况下,我在容器视图中添加了Google登录按钮,其中有Tap Gesture解雇键盘,因为当我点击Google Sign时 - 它曾经没有用过。 我的结局只是有点愚蠢:))

答案 1 :(得分:1)

验证您是否在应用中添加了clientID

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

return true
} 

第二

GIDSignIn.sharedInstance().delegate = self移除行appdelegate并添加您的视图控制器,尝试一次

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

答案 2 :(得分:1)

如果您有敲击手势以关闭键盘...请添加cancelTouchesInView = false:

let endEditingTap = UITapGestureRecognizer(target: self, action: #selector(handleEndEditing))
endEditingTap.cancelsTouchesInView = false
view.addGestureRecognizer(endEditingTap)