如何通过 cocoapods 使用 Google Analytics for iOS [英] How to use Google Analytics for iOS via cocoapods

查看:25
本文介绍了如何通过 cocoapods 使用 Google Analytics for iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的桥接头中,我无限地得到 not found"

我遵循了 Google 自己的教程:

构建设置:

Podfile:

解决方案

Swift 4.0 和 xcode 9.0.1 终于解决了.

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

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

例如在桥接头文件中删除 #import

#import "GAI.h"#import "GAITracker.h"#import "GAIFields.h"#import "GAIDictionaryBuilder.h"

  1. 将您的网桥指向目标 Swift 编译器的构建设置 - 常规 -> Objective-C 桥接标头.写下你的桥接文件名的 Header.h

  2. 将 google for swift 的代码添加到 didFinishLaunchingWithOptions 不要忘记从 Google Analytics 页面替换您的跟踪 ID

     guard 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>

  1. Go to Terminal type pod init
  2. Reopen project as workspace obvious after pod workspace is created, open podfile. write pod 'GoogleAnalytics' in your pod file before target 'GoogleAnalytics' do
  3. Go back to Terminal pod install you will find frameworks GAI.h and other files will be there under pods folder
  4. 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"

  1. Point your bridge under Build Settings for target Swift Compiler - General -> Objective-C Bridging Header. write Header.h of your bridging file name

  2. Add code from google for swift to didFinishLaunchingWithOptions Don't forget to replace your tracking id from Google Analytics page

        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;
    

Tada.... Run your project...

这篇关于如何通过 cocoapods 使用 Google Analytics for iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆