按google登录按钮时什么也没有发生

问题描述 投票:2回答:3

我已经使用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.
        // ...
}

这是我的应用程序代表

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]
}
ios iphone google-plus swift2 google-signin
3个回答
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

6
投票

我不知道是否有人面临这个问题。我知道这可能不是您的情况,但对于其他任何人,我也面临同样的问题,但我的情况是我在Container View中添加了Google登录按钮,该按钮具有Tap Gesture可以关闭键盘,因此当我点击Google Sign时-在,它过去没有用。从我的末端来看只是一个小小的愚蠢:)


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.