First of all need to say that i don\'t use CocoaPods. And it\'s first time when i use Google API.
In Google guide says that i need to configure GIDSignIn in
GGLContext is a part of Google so importing just GoogleSignIn will give you that error. You need to import Google library.
Link to Google Library 2.0.3 https://www.gstatic.com/cpdc/a96d915a636d0afb-Google-2.0.3.tar.gz
To Use Google Sign In. You need to conform to Both GIDSignInDelegate and GIDSignInUIDelegate and Implement delegate Methods.
class LoginViewController: UIViewController, GIDSignInDelegate, GIDSignInUIDelegate {
func viewDidLoad() {
GIDSignIn.sharedInstance().clientID = Resources.googlePlusClientId()
GIDSignIn.sharedInstance().shouldFetchBasicProfile = true
GIDSignIn.sharedInstance().scopes = ["profile", "email"]
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
}
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
}
}
And In AppDelegate
func application(application: UIApplication,
openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
let isFacebookURL = FBSDKApplicationDelegate.sharedInstance().application(application,
openURL: url,
sourceApplication: sourceApplication,
annotation: annotation)
let isGooglePlusURL = GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: sourceApplication,
annotation: annotation)
return isFacebookURL || isGooglePlusURL
}
For swift 5 Xcode 10.3 (Latest google signin)
Replace:
GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: sourceApplication,
annotation: annotation)
With:
GIDSignIn.sharedInstance().handle(url)
On Button click
@IBAction func googleLoginBtnPressed(_ sender: AnyObject) {
GIDSignIn.sharedInstance()?.presentingViewController = self
GIDSignIn.sharedInstance()?.restorePreviousSignIn()
GIDSignIn.sharedInstance().signIn()
}
Remove Delegate: GIDSignInUIDelegate
remove this line from didFinishLaunch GIDSignIn.sharedInstance().delegate = self
and in your view controller class implement GIDSignInDelegate, GIDSignInUIDelegate protocolos
and in your view controller viewDidload method write this
func viewDidLoad() {
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
}
and don't forget to handle url in app delegate.
func application(application: UIApplication,
openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
var flag: Bool = false
// handle Facebook url scheme
if let wasHandled:Bool = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) {
flag = wasHandled
}
if let googlePlusFlag: Bool = GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication!, annotation: annotation) {
flag = googlePlusFlag
}
return flag
}