按下谷歌登录按钮时没有任何反应
Posted
技术标签:
【中文标题】按下谷歌登录按钮时没有任何反应【英文标题】:nothing happen when press google sign in button 【发布时间】:2016-02-13 11:19:04 【问题描述】:我已经使用 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]
【问题讨论】:
【参考方案1】:我不知道其他人是否面临这个问题。我知道这可能不是你的情况,但对于其他任何人来说,我也面临同样的问题,但在我的情况下,我在容器视图中添加了谷歌登录按钮,它有点击手势来关闭键盘,因此当我点击谷歌签名时-在,它以前不工作。 只是我有点愚蠢:)
【讨论】:
对不起,我没有理解你的建议。您是说我们应该将 GIDSignInButton 放在容器视图中吗?那有什么意义呢?我也有同样的问题,即 SFSafariViewController 没有被解除,它只是回退到 www.google.com 而不是解除并返回到我的应用程序界面。 哇,你成就了我的一天 @Shrolox 很高兴我能帮上忙 在我的情况下帮助了这个:) 您有没有找到一种方法让两个 Google 提示(针对用户,然后允许应用程序的范围)出现在容器视图中,而不是填满整个(在我的情况下)iPad 屏幕? 【参考方案2】:验证您是否在应用中添加了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
【讨论】:
关于客户ID;他们从未提到要包含客户 ID。必须从 info.plist 中获取它。但我会试试这个 @GishanthaJayasooriya -- 如果你在这里没有得到答案,请尝试一次,我会支持你riskcompletefailure.com/2015/03/google-sign-in-ios-100.html 我已尝试提供客户端 ID。但我不能分配 GIDSignIn.sharedInstance().delegate = self 因为我在我的 uiviewControllar 中使用了 GIDSignInUIDelegate。我现在能做什么 好的,检查更新答案,把断点放在你的didSignInForUser中,检查一次【参考方案3】:如果您有点击手势来关闭键盘...添加 cancelTouchesInView=false:
let endEditingTap = UITapGestureRecognizer(target: self, action: #selector(handleEndEditing))
endEditingTap.cancelsTouchesInView = false
view.addGestureRecognizer(endEditingTap)
【讨论】:
以上是关于按下谷歌登录按钮时没有任何反应的主要内容,如果未能解决你的问题,请参考以下文章