使用 GIDSignIn 通过另一个 Google 应用程序处理登录时不获取 Google 用户 [英] Not fetch Google user when handle sign in with another Google app using GIDSignIn

查看:21
本文介绍了使用 GIDSignIn 通过另一个 Google 应用程序处理登录时不获取 Google 用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 iOS 版 Google 登录并且当使用模拟器时它工作正常,因为没有安装谷歌应用程序并且用户正在获取,但是当使用我的 iPhone 6 设备时打开 youtube(其中有一些注册帐户)进行句柄登录.之后,当回到应用程序代码时不要在此功能上输入:

I'm using Google Sign-In for iOS and when using simulator it's working fine because no google app is installed and user is fetch, but when using my iPhone 6 device open youtube (with some registered account inside them) for handle sign in. After, when come back on the app code don't enter on this function :

-(void)signIn:(GIDSignIn *) signIn 
    didSignInForUser:(GIDGoogleUser *)
    user withError:(NSError *) error

任何人都可以帮助我我不能使用其他功能登录我必须调用 [[GIDSignIn sharedIstance] signIn] 并且此功能检测是否安装了另一个谷歌应用程序并自动打开另一个谷歌应用程序或网络视图.

Anyone can help me i can't use another function for login i must call [[GIDSignIn sharedIstance] signIn] and this function detect if another google app is installed and automatically open another google app or Webview.

推荐答案

import UIKit
import GoogleSignIn
import Google

class ViewController: UIViewController,GIDSignInUIDelegate, GIDSignInDelegate {

override func viewDidLoad() {
    super.viewDidLoad()
    let gidSingIn = GIDSignIn()

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

    var configureError:NSError?
    GGLContext.sharedInstance().configureWithError(&configureError)

    assert(configureError == nil, "Error configuring Google services: \(configureError)")


    let button = GIDSignInButton(frame:CGRectMake(0,0,30, 200))
        button.center = self.view.center
        button.backgroundColor = UIColor.blueColor()
       self.view.addSubview(button)



    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func signInGoogle(sender: AnyObject) {

    print("pressed")

}

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
            withError error: NSError!) {
    if (error == nil) {
        // Perform any operations on signed in user here.
        print(user.userID)                // For client-side use only!
        print(user.authentication.idToken) // Safe to send to the server
        print(user.profile.name)
        print(user.profile.givenName)
        print(user.profile.familyName)
        print(user.profile.email)
        print(user.authentication.accessToken)
        print(user.profile)
    } else {
        print("\(error.localizedDescription)")
    }
}
func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!,
            withError error: NSError!) {
}

}//这是使用 gmail 帐户登录,不适用于 googleplus.只需在您的控制器中复制和过去即可.并在您的 AppDelegate 类中添加以下功能

} // this is login with gmail account not for googleplus. just copy and past within your controller. and add following func in your AppDelegate Class

func application(application: UIApplication,
                 openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    var options: [String: AnyObject] = [UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication!,UIApplicationOpenURLOptionsAnnotationKey: annotation]
    return GIDSignIn.sharedInstance().handleURL(url,
                                                sourceApplication: sourceApplication,
                                                annotation: annotation)
}

这篇关于使用 GIDSignIn 通过另一个 Google 应用程序处理登录时不获取 Google 用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆