iOS Swift : google 登录错误
iOS Swift : error with google login
我正在按照 this 教程使用 swift 在我的 iOS 应用程序中添加 google 登录。我按照提到的所有步骤进行操作,但是当我尝试构建应用程序时,它在我的 appdelegate.swift 文件中给了我一个问题。
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
}
所以在代码行下面
GGLContext.sharedInstance().configureWithError(&configureError)
错误文本是 "Use of unresolved identifier GGLContext"。这里可能是什么问题?
我找到了解决方案,您可以使用 Bridge-Header.h 文件并像那样导入
#ifndef Bridge_header_h
#define Bridge_header_h
#import "Google/Core.h"
#import "GoogleSignIn.h"
#endif /* Bridge_header_h */
它在我这边工作得很好。
在桥接中-Header.h
import <GoogleSignIn/GoogleSignIn.h>
import <Google/Core.h>
在AppDelegate.swift
import Google
初步:
当我集成 Cocoapod Google/SignIn 时收到 Thread 警告,这几天我一直很生气。在深入研究所有内容之后,我可能找到了解决方案。如果您希望项目中 google 的唯一方面是登录,那么这可能只是值得一看的东西。如果您集成了 Firebase 或 google 的任何其他部分,您可能永远不会遇到导致您转到此线程的问题。
好的,在深入研究这个问题后,我发现我的解决方案是:
仅在桥接头中导入#import <GoogleSignIn/GoogleSignIn.h>
仅在 AppDelegate 中导入 import GoogleSignIn
仅在 Podfile 导入中 pod 'GoogleSignIn'
在 AppDelegate didFinishLaunchingWithOptions 中做这样的事情:
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
并删除:
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError!)")
使用此设置,一切似乎都运行良好。我通过查看下面的 link 得到了这个想法。如果这对你有用,请告诉我。
在 swift 中,以下对我有用。
导入 GoogleSignIn
我正在按照 this 教程使用 swift 在我的 iOS 应用程序中添加 google 登录。我按照提到的所有步骤进行操作,但是当我尝试构建应用程序时,它在我的 appdelegate.swift 文件中给了我一个问题。
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
}
所以在代码行下面
GGLContext.sharedInstance().configureWithError(&configureError)
错误文本是 "Use of unresolved identifier GGLContext"。这里可能是什么问题?
我找到了解决方案,您可以使用 Bridge-Header.h 文件并像那样导入
#ifndef Bridge_header_h
#define Bridge_header_h
#import "Google/Core.h"
#import "GoogleSignIn.h"
#endif /* Bridge_header_h */
它在我这边工作得很好。
在桥接中-Header.h
import <GoogleSignIn/GoogleSignIn.h>
import <Google/Core.h>
在AppDelegate.swift
import Google
初步:
当我集成 Cocoapod Google/SignIn 时收到 Thread 警告,这几天我一直很生气。在深入研究所有内容之后,我可能找到了解决方案。如果您希望项目中 google 的唯一方面是登录,那么这可能只是值得一看的东西。如果您集成了 Firebase 或 google 的任何其他部分,您可能永远不会遇到导致您转到此线程的问题。
好的,在深入研究这个问题后,我发现我的解决方案是:
仅在桥接头中导入#import <GoogleSignIn/GoogleSignIn.h>
仅在 AppDelegate 中导入 import GoogleSignIn
仅在 Podfile 导入中 pod 'GoogleSignIn'
在 AppDelegate didFinishLaunchingWithOptions 中做这样的事情:
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
并删除:
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError!)")
使用此设置,一切似乎都运行良好。我通过查看下面的 link 得到了这个想法。如果这对你有用,请告诉我。
在 swift 中,以下对我有用。
导入 GoogleSignIn