悬而未决的标识符GGLContext和GAI使用

问题描述 投票:25回答:5

我有一个有点麻烦。我试图谷歌分析安装到应用程序和我始终得到使用未解决的标识符GGLContextGAI错误的。我收到了同样的错误,我是否使用的CocoaPods与否。错误的位置是在这里AppDelegate.swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

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

    // Optional: configure GAI options.
    let gai = GAI.sharedInstance()
    gai.trackUncaughtExceptions = true  // report uncaught exceptions

    return true
}

没有什么额外的能够被导入到AppDelegate.swift(如谷歌),只是标准UIKit

我经历过很多教程和其他SO问题,都无济于事。我想,有我缺少一些小东西,但无法找到它。

我做了什么:

我有.h文件在我的项目,与libGoogleAnalyticsServices.alibsqlite3.0.tbdlibz.tbdlibsqlite3.tbd(所有这些都被链接到库以及CoreData和SystemConfiguration)一起。

你可以在这里看到所有这些文件的布局:

enter image description here

和这里:

enter image description here

我创建了-Bridging-Header.h并包含在它这些.h进口。

#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIEcommerceFields.h"
#import "GAIEcommerceProduct.h"
#import "GAIEcommerceProductAction.h"
#import "GAIEcommercePromotion.h"
#import "GAIFields.h"
#import "GAILogger.h"
#import "GAITrackedViewController.h"
#import "GAITracker.h"

-Bridging-Header.h在构建设置链接,我收到没有错误。这是我的研究,这并没有帮助我在这种情况下时,我发现的主要解决方案。

我试图从头开始用的CocoaPods两次,并没有(我开始之前我做项目的一个副本),我每次都收到了同样的错误。

任何帮助将肯定可以理解的。提前致谢。

xcode swift google-analytics swift2
5个回答
16
投票

好了,它看起来像我能得到它的平方了。

有几个问题,在这一切的尝试。

  1. 的CocoaPods没有正确安装。我重新安装了,然后有更好的成功导入正确的文件。
  2. 做手工,如我上面贴是不是最好的选择。
  3. 在之后的CocoaPods重新安装,并从我的项目的最新副本重新开始,我能够import Google到我AppDelegate.swift

对于那些谁可以在同一条船上我是在最后关键点:

  • 一定要添加正确的目录为您-Bridging-Header.h。您可以根据项目找到这个 - 构建设置 - 斯威夫特编译器代码生成。使用此轻松地定位你的头文件$(SWIFT_MODULE_NAME)-Bridging-Header.h
  • 在你-Bridging-Header.h,不#import <Google/Analytics.h>,而不是分别导入文件。下面是可用的要导入的文件的图像。

enter image description here

  • 如果有疑问,重新安装的CocoaPods
  • 不要相信谷歌教程,提供最有效的指令,并利用多那么的这篇文章。

我真的希望这可以帮助别人不花10个小时的问题,因为我有。


13
投票

雨燕4.0和9.0.1的Xcode我终于解决了。

对我来说,2天之后,我决定..不要效仿谷歌的旧文件说#import <Google/Analytics.h>

  1. 转到终端类型pod init
  2. 作为工作区工作区荚后明显被创建,打开podfile重新打开项目。在pod 'GoogleAnalytics'之前,你的吊舱文件写target 'GoogleAnalytics' do
  3. 回到码头pod install你会发现框架GAI.h和其他文件将在那里荚文件夹下
  4. 创建Header.h文件到您的根。不要添加#import <Google/Analytics.h>替代导入单独按照桥接报头文件

例如在桥接报头文件中删除#import <Google/Analytics.h>

#import GAI.h
#import "GAITracker.h"
#import "GAIFields.h"
#import "GAIDictionaryBuilder.h"
  1. 点目标斯威夫特编译器生成设置下的桥梁 - 通用 - > Objective-C的桥接报头。写Header.h你的桥接文件名
  2. 从谷歌添加代码为迅速给didFinishLaunchingWithOptions不要忘了从谷歌Analytics(分析)页面替换您的跟踪ID guard let gai = GAI.sharedInstance() else { assert(false, "Google Analytics not configured correctly") } gai.tracker(withTrackingId: "YOUR_TRACKING_ID") // Optional: automatically report uncaught exceptions. gai.trackUncaughtExceptions = true // Optional: set Logger to VERBOSE for debug information. // Remove before app release. gai.logger.logLevel = .verbose;

田田....运行您的项目...


9
投票

我的错误是使用未解决的标识符时,我用的是单GAI.sharedInstance()

我的步骤,使这项工作是:

  1. 添加pod 'Google/Analytics'
  2. 吊舱安装
  3. 重新启动的Xcode
  4. 在我的项目获得桥接报创建objc类
  5. 到桥接报头添加文件#import "GAI.h"

一切完美。


9
投票

这适用于SWIFT 2.3,SWIFT 3.0和SWIFT 4:

  1. 在GoogleService-Info.plist文件添加到您的项目的根
  2. 这增加了podfile: pod 'Google/Analytics'
  3. 退出Xcode中,运行“荚安装”在终端和开放的Xcode再次
  4. 在项目中创建的根,叫转职Header.h一个头文件,下生成设置确保桥接报头被定义像图片enter image description here
  5. 确保你的桥接,Header.h看起来是这样的: #ifndef Bridging_Header_h #define Bridging_Header_h #import <Google/Analytics.h> #endif /* Bridging_Header_h */
  6. 添加到AppDelegate中: import Google
  7. 添加该代码在didFinishLaunchingWithOptions方法的appdelegate: // Configure tracker from GoogleService-Info.plist. var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services:\(configureError)") // Optional: configure GAI options. guard let gai = GAI.sharedInstance() else { assert(false, "Google Analytics not configured correctly") } gai.trackUncaughtExceptions = true // report uncaught exceptions gai.logger.logLevel = GAILogLevel.Verbose // remove before app release

如果有错误,删除DerivedData和清洁项目可以提供帮助。


0
投票

只有这样,才能使工作对我来说是降级谷歌Analytics(分析)吊舱版本2.0.4。

由谷歌/分析,B〜> 2.0.ch

© www.soinside.com 2019 - 2024. All rights reserved.