iOS Swift : error with google login

旧时模样 提交于 2019-12-01 14:09:26

问题


I was following this tutorial to add google sign in in my iOS app using swift. I followed all the steps as mentioned but when I try to build app then it is giving me an issue in my appdelegate.swift file.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    var configureError: NSError?
    GGLContext.sharedInstance().configureWithError(&configureError)
    assert(configureError == nil, "Error configuring Google services: \(configureError)")

    GIDSignIn.sharedInstance().clientID = "client id"

    return true

}

so below line of code

GGLContext.sharedInstance().configureWithError(&configureError)

Error text is "Use of unresolved identifier GGLContext". What could be the issue here ?


回答1:


I found the solution, You can use the Bridge-Header.h file and import like that

#ifndef Bridge_header_h
#define Bridge_header_h

#import "Google/Core.h"
#import "GoogleSignIn.h"

#endif /* Bridge_header_h */

it's work perfectly at my end.




回答2:


in Bridging-Header.h

import <GoogleSignIn/GoogleSignIn.h>

import <Google/Core.h>

in AppDelegate.swift

import Google



回答3:


Preliminary:

I have been annoyed for a few days now that when I integrated the Cocoapod Google/SignIn that I was getting Thread warnings. After digging into everything, I may have found a solution. This probably would only be something worth looking at if the only aspect of google you want in your project in sign in. If you have Firebase or any other part of google integrated, you probably will never hit an issue that leads you to this thread though.

OK, after delving into this problem for a bit, I found my solution to be:

In Bridging Header import only #import <GoogleSignIn/GoogleSignIn.h>

In AppDelegate import only import GoogleSignIn

In Podfile import only pod 'GoogleSignIn'

In AppDelegate didFinishLaunchingWithOptions do domething like this:

if let path = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist"),
    let googleInfo = NSDictionary(contentsOfFile: path),
    let clientId = googleInfo["CLIENT_ID"] as? String {
    GIDSignIn.sharedInstance().clientID = clientId
}
GIDSignIn.sharedInstance().delegate = self

and remove:

var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError!)")

With this setup, everything seems to be working great. I got the idea by looking at the link below. Let me know if this works for you.

https://github.com/googlesamples/google-services/blob/master/ios/signin/SignInExampleSwift/AppDelegate.swift




回答4:


in swift, the below worked for me.

import GoogleSignIn



来源:https://stackoverflow.com/questions/31626693/ios-swift-error-with-google-login

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!