我有一个有点麻烦。我试图谷歌分析安装到应用程序和我始终得到使用未解决的标识符GGLContext
和GAI
错误的。我收到了同样的错误,我是否使用的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.a
,libsqlite3.0.tbd
,libz.tbd
,libsqlite3.tbd
(所有这些都被链接到库以及CoreData和SystemConfiguration)一起。
你可以在这里看到所有这些文件的布局:
和这里:
我创建了-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两次,并没有(我开始之前我做项目的一个副本),我每次都收到了同样的错误。
任何帮助将肯定可以理解的。提前致谢。
好了,它看起来像我能得到它的平方了。
有几个问题,在这一切的尝试。
import Google
到我AppDelegate.swift
。对于那些谁可以在同一条船上我是在最后关键点:
-Bridging-Header.h
。您可以根据项目找到这个 - 构建设置 - 斯威夫特编译器代码生成。使用此轻松地定位你的头文件$(SWIFT_MODULE_NAME)-Bridging-Header.h
-Bridging-Header.h
,不#import <Google/Analytics.h>
,而不是分别导入文件。下面是可用的要导入的文件的图像。我真的希望这可以帮助别人不花10个小时的问题,因为我有。
雨燕4.0和9.0.1的Xcode我终于解决了。
对我来说,2天之后,我决定..不要效仿谷歌的旧文件说#import <Google/Analytics.h>
pod init
pod 'GoogleAnalytics'
之前,你的吊舱文件写target 'GoogleAnalytics' do
pod install
你会发现框架GAI.h
和其他文件将在那里荚文件夹下Header.h
文件到您的根。不要添加#import <Google/Analytics.h>
替代导入单独按照桥接报头文件例如在桥接报头文件中删除#import <Google/Analytics.h>
#import GAI.h
#import "GAITracker.h"
#import "GAIFields.h"
#import "GAIDictionaryBuilder.h"
Header.h
你的桥接文件名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;
田田....运行您的项目...
我的错误是使用未解决的标识符时,我用的是单GAI.sharedInstance()
。
我的步骤,使这项工作是:
pod 'Google/Analytics'
#import "GAI.h"
一切完美。
这适用于SWIFT 2.3,SWIFT 3.0和SWIFT 4:
pod 'Google/Analytics'
#ifndef Bridging_Header_h
#define Bridging_Header_h
#import <Google/Analytics.h>
#endif /* Bridging_Header_h */
import Google
// 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和清洁项目可以提供帮助。
只有这样,才能使工作对我来说是降级谷歌Analytics(分析)吊舱版本2.0.4。
由谷歌/分析,B〜> 2.0.ch