[英]Google Analytics with Swift 3 iOS 9
I tried to find informations about how to use Google Analytics with Swift 3, and even if it looks like some people succeeded, I can't make it work myself. 我试图找到有关如何在Swift 3中使用Google Analytics(分析)的信息,即使看起来有些成功,我也无法自己使用。
The Google Analytics documentation doesn't help, it's only for working for Swift 2. Google Analytics(分析)文档无济于事,仅适用于Swift 2。
I used the pod "Google/Analytics" in version 3.17.0 and tried to add this line inside a bridging header file as some people mentioned : 我在3.17.0版中使用了“ Google / Analytics”广告连播,并尝试将这一行添加到桥接头文件中,就像有人提到的那样:
#import <Google/Analytics.h>
But I got an error about Xcode complaining that bridging headers doesn't work with Swift 3. 但是我遇到了一个关于Xcode的错误,抱怨桥接标头在Swift 3中不起作用。
Then I tried to add the same line inside the .h as another post suggest, but doesn't work neither, Xcode complains "Include of non-modular header inside framework module XXX". 然后,我尝试在.h内添加同一行,如另一篇文章所建议的那样,但两者都不起作用,Xcode抱怨“框架模块XXX内包含非模块化标头”。
I tried to set "Allow Non-modular Includes in Framework Modules to YES but it doesn't change anything, still got the same error. 我试图将“允许框架模块中的非模块化包含”设置为“是”,但它没有任何改变,仍然出现相同的错误。
Last thing I tried is to add : 我尝试的最后一件事是添加:
import Google
Inside the file where I use Google Analytics, but now GAI is not recognized. 在我使用Google Analytics(分析)的文件中,但现在无法识别GAI。
// 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
Any suggestions ? 有什么建议么 ?
Follow these steps in order to configure Google Analytics 请按照以下步骤配置Google Analytics(分析)
Create a Bridging file in your project if there is already one exists then no need to recreate it. 如果项目中已经存在一个桥接文件,则无需重新创建它。
5.1. 5.1。 To create a bridging file the easiest way is to add/create new objective-c class to the project and the option pops up which ask you to create a bridging file and it sets all of the setting by default.
要创建桥接文件,最简单的方法是在项目中添加/创建新的Objective-C类,并弹出选项,要求您创建桥接文件,并且默认情况下设置所有设置。
" #import <Google/Analytics.h> "
" #import <Google/Analytics.h> "
Open " AppDelegate.swift " and copy and paste the below code in didFinishLaunchingWithOptions for setting the Analytics tracker 打开“ AppDelegate.swift ”,然后将以下代码复制并粘贴到didFinishLaunchingWithOptions中,以设置Google Analytics(分析)跟踪器
// 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
Build your project. 建立您的专案。
I hope it works if there is any problem then let me know. 我希望如果有任何问题,请告诉我。
I faced the same problem. 我遇到了同样的问题。 I could not import the "Google/Analytics.h" header as Xcode generate error.
由于Xcode生成错误,我无法导入“ Google / Analytics.h”标头。 Because "Google/Analytics.h" header is not available in the 'GoogleAnalytics sdk' as mentioned in Google's Official page.
因为Google的官方页面中提到的“ GoogleAnalytics sdk”中没有“ Google / Analytics.h”标头。 So, i just used following line in AppDelegete.m file
所以,我只是在AppDelegete.m文件中使用了以下行
#import "AppDelegate.h"
#import "GAI.h"
Hope it will work just fine. 希望它会很好。 Environment Xcode: 8.2 iOS :10.2
环境Xcode:8.2 iOS:10.2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.