如何通过cocoapods使用Google Analytics for iOS

Chr*_*son 6 google-analytics cocoapods swift3 xcode8

在我的桥接标题中,我无限地得到"<Google/Analytics.h> not found"

我按照谷歌自己的教程:https://developers.google.com/analytics/devguides/collection/ios/v3/?ver = swift

我尝试过人们发布的'pod GoogleAnalytics'方法.

我已经尝试了人们在其他主题中发布的所有建议.

我还需要在"构建设置"中更改其他内容吗?或者"pod install"是否可以执行所有操作?


桥接标题: 桥接标题

构建设置: 构建设置

Podfile: Podfile

kar*_*ran 16

最后我解决了Swift 4.0和xcode 9.0.1.

对我来说,2天后我解决了..不要按照Google的旧文档说 #import <Google/Analytics.h>

  1. 转到终端类型 pod init
  2. 创建pod工作区后,重新打开项目作为工作区,打开podfile.之前写pod 'GoogleAnalytics'在你的pod文件中target 'GoogleAnalytics' do
  3. 回到终端pod install你会发现框架GAI.h和其他文件将在pods文件夹下
  4. 创建Header.h根目录的文件.不要#import <Google/Analytics.h>在桥接头文件中单独添加以下导入

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

#import "GAI.h"
#import "GAITracker.h"
#import "GAIFields.h"
#import "GAIDictionaryBuilder.h"
Run Code Online (Sandbox Code Playgroud)
  1. 将您的网桥指向目标Swift编译器的Build Settings下 - General - > Objective-C Bridging Header.写下Header.h您的桥接文件名

  2. 从google for swift添加代码didFinishLaunchingWithOptions 不要忘记从Google 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;
    
    Run Code Online (Sandbox Code Playgroud)

田田....运行你的项目......