使用Swift的CocoaPods 0.36上的GoogleAnalytics-iOS-SDK [英] GoogleAnalytics-iOS-SDK on CocoaPods 0.36 with Swift

查看:141
本文介绍了使用Swift的CocoaPods 0.36上的GoogleAnalytics-iOS-SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道如何使用CocoaPods 0.36为Swift编写桥接头?

Anyone knows How do I write Bridging Header for Swift with CocoaPods 0.36?

我试过这些方法。

(1)

#import <GoogleAnalytics-iOS-SDK/GAI.h>

=>这是cocoapods 0.35风格。无法编译。

=> this is cocoapods 0.35 style. failed to compile.

(2)

#import <GoogleAnalytics-iOS-SDK/GoogleAnalytics-iOS-SDK/GAI.h>

=>编译失败。

(3)

#import "../Pods/GoogleAnalytics-iOS-SDK/GoogleAnalytics/Library/GAI.h"

=>可以遵守。但链接失败。

=> it can be complied. but failed linking.

推荐答案

我设法通过Cocoapods将Google Analytics iOS SDK 3.10成功地包含在我的Swift项目中,使用框架按照这些步骤操作。

I managed to successfully include Google Analytics iOS SDK 3.10 via Cocoapods into my Swift project using frameworks following these steps.

在Podfile上添加(注意 use_frameworks!):

On the Podfile add (note the use_frameworks!):

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target "XXXX" do
    pod 'GoogleAnalytics-iOS-SDK', '~> 3.10'
end

target "XXXXTests" do
    pod 'GoogleAnalytics-iOS-SDK', '~> 3.10'
end

AppDelegate 导入部分添加:

import GoogleAnalytics_iOS_SDK

应用程序上,didFinishLaunchingWithOptions 方法添加:

    GAI.sharedInstance().trackUncaughtExceptions = true
    GAI.sharedInstance().dispatchInterval = 20
    GAI.sharedInstance().logger.logLevel = GAILogLevel.Verbose
    GAI.sharedInstance().trackerWithTrackingId("XXXX")
    GAI.sharedInstance().defaultTracker.allowIDFACollection = true

此时,您的代码将无法编译。您需要手动向目标添加其他依赖项,包括应用程序和单元测试(如 https://developers.google.com/analytics/devguides/collection/ios/v3/#headers )。

At this point, your code won't compile. You need to add other dependencies manually to your targets, both the application and the unit tests (as indicated at https://developers.google.com/analytics/devguides/collection/ios/v3/#headers).


  • CoreData.framework

  • SystemConfiguration.framework

  • libz.dylib

  • libsqlite3。 dylib

  • libGoogleAnalyticsServices.a

  • CoreData.framework
  • SystemConfiguration.framework
  • libz.dylib
  • libsqlite3.dylib
  • libGoogleAnalyticsServices.a

请注意 libGoogleAnalyticsServices.a 。出于某种原因,Cocoapods在使用框架时不包括此内容。如果不添加此文件,链接器将失败并显示以下错误:

Notice the libGoogleAnalyticsServices.a. For some reason, this is not included by Cocoapods when using frameworks. Without adding this file, the linker will fail with the following error:

Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_GAI", referenced from: __TMaCSo3GAI in AppDelegate.o

为了添加它,我手动下载了SDK(从此页面: https://developers.google.com/analytics/devguides/collection/ ios / resources )并将 libGoogleAnalyticsServices.a 拖到我的项目中,确保它已添加到两个目标中并检查了复制复选框。

In order to add it, I downloaded the SDK manually (from this page: https://developers.google.com/analytics/devguides/collection/ios/resources) and dragged the libGoogleAnalyticsServices.a to my project making sure it was added to both targets and the 'copy' checkbox was checked.

在添加文件和其他提到的依赖项之后,项目正确构建。

After adding the file and other mentioned dependencies the project builds properly.

好像Cocoapods只包含来自Google的头文件Analytics SDK。此解决方案并不完美,但无需为Google Analytics添加桥接标头。

It seems as if Cocoapods was including nothing but the header files from the Google Analytics SDK. This solution is not perfect but avoids requiring to add a bridging header just for Google Analytics.

这篇关于使用Swift的CocoaPods 0.36上的GoogleAnalytics-iOS-SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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