ios – 使用GIDSignIn处理使用其他Google应用登录时,不会获取Google用户

我正在使用 Google Sign-In for iOS,当使用模拟器它工作正常,因为没有安装谷歌应用程序和用户获取,但当使用我的iPhone 6设备打开youtube(其中有一些注册帐户)的句柄登录.
之后,当回到应用程序代码时,请不要输入此功能:
-(void)signIn:(GIDSignIn *) signIn 
    didSignInForUser:(GIDGoogleUser *)
    user withError:(NSError *) error

任何人都可以帮助我我不能使用其他功能登录我必须调用[[GIDSignIn sharedIstance] signIn]并且此功能检测是否安装了另一个谷歌应用程序并自动打开另一个谷歌应用程序或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,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类中添加以下func

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

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...