按 google 登录按钮时没有任何反应
nothing happen when press google sign in button
我已经使用 pods.and 为 ios 配置了 Google SDK 我添加了一个 uiview 作为登录按钮(将 class 设置为 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]
}
验证一次您是否在您的应用中添加了 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
我不知道是否还有其他人遇到过这个问题。我知道这可能不是你的情况,但对于其他人来说,我也面临同样的问题,但在我的情况下,我在容器视图中添加了 Google 登录按钮,该按钮具有用于关闭键盘的点击手势,因此当我点击 Google 登录 ,它以前没有用。
我这边有点愚蠢:)
如果您有一个点击手势来关闭键盘...添加 cancelsTouchesInView=false:
let endEditingTap = UITapGestureRecognizer(target: self, action: #selector(handleEndEditing))
endEditingTap.cancelsTouchesInView = false
view.addGestureRecognizer(endEditingTap)
我已经使用 pods.and 为 ios 配置了 Google SDK 我添加了一个 uiview 作为登录按钮(将 class 设置为 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]
}
验证一次您是否在您的应用中添加了 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
我不知道是否还有其他人遇到过这个问题。我知道这可能不是你的情况,但对于其他人来说,我也面临同样的问题,但在我的情况下,我在容器视图中添加了 Google 登录按钮,该按钮具有用于关闭键盘的点击手势,因此当我点击 Google 登录 ,它以前没有用。 我这边有点愚蠢:)
如果您有一个点击手势来关闭键盘...添加 cancelsTouchesInView=false:
let endEditingTap = UITapGestureRecognizer(target: self, action: #selector(handleEndEditing))
endEditingTap.cancelsTouchesInView = false
view.addGestureRecognizer(endEditingTap)