iOS Swift:谷歌登录时出错

Ani*_*man 12 google-login ios swift

我正在按照教程使用swift在我的iOS应用中添加谷歌登录.我按照提到的所有步骤进行了操作,但是当我尝试构建应用程序时,它在我的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

}
Run Code Online (Sandbox Code Playgroud)

所以下面的代码行

GGLContext.sharedInstance().configureWithError(&configureError)
Run Code Online (Sandbox Code Playgroud)

错误文本是"使用未解析的标识符GGLContext".这可能是什么问题?

Dat*_*kar 5

在Bridging-Header.h中

import <GoogleSignIn/GoogleSignIn.h>

import <Google/Core.h>
Run Code Online (Sandbox Code Playgroud)

在AppDelegate.swift中

import Google
Run Code Online (Sandbox Code Playgroud)

  • ^该版本实际上根本不是问题,应该已经明确我的问题是无关的bc cocoapod框架不需要桥接头.以防其他人在使用Cocoapods安装时结束这个问题:有一个名为`GoogleSignIn`的pod是我所包含的,但这是错误的,没有所有必要的依赖.您需要安装依赖于Google框架的"Google/SignIn"(以及一堆看似无关的FirebaseCore和FirebaseAnalytics).使用正确的pod,文档说明是正确的. (3认同)

Tom*_*yer 1

我找到了解决方案,您可以使用 Bridge-Header.h 文件并像这样导入

#ifndef Bridge_header_h
#define Bridge_header_h

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

#endif /* Bridge_header_h */
Run Code Online (Sandbox Code Playgroud)

它在我这边工作得很好。