如何通过 cocoapods 使用 Google Analytics for iOS [英] How to use Google Analytics for iOS via cocoapods
问题描述
在我的桥接头中,我无限地得到
我遵循了 Google 自己的教程:
构建设置:
Podfile:
Swift 4.0 和 xcode 9.0.1 终于解决了.
对我来说,2 天后我解决了.. 不要按照 Google 的旧文档说 #import <Google/Analytics.h>
- 转到终端类型
pod init
- 在创建 pod 工作区后重新打开项目作为工作区明显,打开 podfile.在
target 'GoogleAnalytics' do
之前在您的 pod 文件中写入 - 回到终端
pod install
你会发现框架GAI.h
和其他文件会在pods文件夹下 - 创建
Header.h
文件到你的根目录.不要添加#import
而是在桥接头文件中单独导入以下内容
pod 'GoogleAnalytics'
例如在桥接头文件中删除 #import
#import "GAI.h"#import "GAITracker.h"#import "GAIFields.h"#import "GAIDictionaryBuilder.h"
将您的网桥指向目标 Swift 编译器的构建设置 - 常规 -> Objective-C 桥接标头.写下你的桥接文件名的
Header.h
将 google for swift 的代码添加到
didFinishLaunchingWithOptions
不要忘记从 Google Analytics 页面替换您的跟踪 IDguard let gai = GAI.sharedInstance() else {assert(false, "Google Analytics 配置不正确")}gai.tracker(withTrackingId: "YOUR_TRACKING_ID")//可选:自动报告未捕获的异常.gai.trackUncaughtExceptions = true//可选:将 Logger 设置为 VERBOSE 以获取调试信息.//在应用发布前移除.gai.logger.logLevel = .verbose;
Tada....运行你的项目...
In my bridging header, I infinitely get "<Google/Analytics.h> not found"
I followed Google's own tutorial: https://developers.google.com/analytics/devguides/collection/ios/v3/?ver=swift
I've tried the 'pod GoogleAnalytics' methods people have posted.
I've tried all of the suggestions people have posted in other threads.
Is there something else I need to change in the "build settings" ... or does 'pod install' do everything?
Bridging Header:
Build Settings:
Podfile:
Swift 4.0 and xcode 9.0.1 finally I resolved.
For me after 2 days I resolved.. Don't follow Google's old documentation says #import <Google/Analytics.h>
- Go to Terminal type
pod init
- Reopen project as workspace obvious after pod workspace is created, open podfile. write
pod 'GoogleAnalytics'
in your pod file beforetarget 'GoogleAnalytics' do
- Go back to Terminal
pod install
you will find frameworksGAI.h
and other files will be there under pods folder - Create
Header.h
file to your root. Don't add#import <Google/Analytics.h>
instead import following individually in bridging header file
e.g. in bridging header file remove #import <Google/Analytics.h>
#import "GAI.h"
#import "GAITracker.h"
#import "GAIFields.h"
#import "GAIDictionaryBuilder.h"
Point your bridge under Build Settings for target Swift Compiler - General -> Objective-C Bridging Header. write
Header.h
of your bridging file nameAdd code from google for swift to
didFinishLaunchingWithOptions
Don't forget to replace your tracking id from Google Analytics pageguard 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;
Tada.... Run your project...
这篇关于如何通过 cocoapods 使用 Google Analytics for iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!