简体   繁体   English

使用Swift的CocoaPods 0.36上的GoogleAnalytics-iOS-SDK

[英]GoogleAnalytics-iOS-SDK on CocoaPods 0.36 with Swift

Anyone knows How do I write Bridging Header for Swift with CocoaPods 0.36? 任何人都知道如何使用CocoaPods 0.36为Swift编写桥接头?

I tried these ways. 我试过这些方法。

(1) (1)

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

=> this is cocoapods 0.35 style. =>这是cocoapods 0.35风格。 failed to compile. 无法编译。

(2) (2)

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

=> failed to compile. =>编译失败。

(3) (3)

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

=> it can be complied. =>它可以被遵守。 but failed linking. 但链接失败。

I managed to successfully include Google Analytics iOS SDK 3.10 via Cocoapods into my Swift project using frameworks following these steps. 我设法通过Cocoapods将Google Analytics iOS SDK 3.10成功地包含在我的Swift项目中,并按照这些步骤使用框架。

On the Podfile add (note the use_frameworks! ): 在Podfile上添加(注意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

On the AppDelegate import section add: AppDelegate导入部分添加:

import GoogleAnalytics_iOS_SDK

On the application didFinishLaunchingWithOptions method add: application didFinishLaunchingWithOptions方法中添加:

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

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 ). 您需要手动将其他依赖项添加到目标,包括应用程序和单元测试(如https://developers.google.com/analytics/devguides/collection/ios/v3/#headers所示 )。

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

Notice the libGoogleAnalyticsServices.a . 请注意libGoogleAnalyticsServices.a For some reason, this is not included by Cocoapods when using frameworks. 出于某种原因,Cocoapods在使用框架时不包含此内容。 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

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. 为了添加它,我手动下载了SDK(从此页面: https//developers.google.com/analytics/devguides/collection/ios/resources )并将libGoogleAnalyticsServices.a拖到我的项目中,确保它已添加两个目标和'复制'复选框已被选中。

在此输入图像描述

After adding the file and other mentioned dependencies the project builds properly. 添加文件和其他提到的依赖项后,项目正确构建。

It seems as if Cocoapods was including nothing but the header files from the Google Analytics SDK. 好像Cocoapods只包含Google AnalyticsSDK中的头文件。 This solution is not perfect but avoids requiring to add a bridging header just for Google Analytics. 此解决方案并不完美,但避免了仅为Google Analytics添加桥接标头。

I had a similar problem on CocoaPods 0.39.0. 我在CocoaPods 0.39.0上遇到了类似的问题。

$(inherited) in build setting 'OTHER_LDFLAGS' solved it. 构建设置'OTHER_LDFLAGS'中的$(继承)解决了它。

https://stackoverflow.com/a/32004207/3129306 https://stackoverflow.com/a/32004207/3129306

Having the same issue currently... 目前有同样的问题......

I got the bridging header to work by using: 我通过使用以下方式使用桥接头工作:

#import <GoogleAnalytics_iOS_SDK/GAI.h>
#import <GoogleAnalytics_iOS_SDK/GAITrackedViewController.h>
#import <GoogleAnalytics_iOS_SDK/GAIDictionaryBuilder.h>
#import <GoogleAnalytics_iOS_SDK/GAIFields.h>

Unfortunately, while this passes the build, I cannot use it in my project. 不幸的是,虽然这通过了构建,但我不能在我的项目中使用它。 I will update if I find more... 如果我找到更多,我会更新...

When using a bridging header, you should be able to import the Google Analytics iOS SDK by using the following import statement: 使用桥接标头时,您应该可以使用以下import语句导入Google Analytics iOS SDK:

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

If you're using pods as frameworks (by setting 'use_frameworks!' in your podfile), you don't need the bridging file. 如果您使用pod作为框架(通过在podfile中设置'use_frameworks!'),则不需要桥接文件。 In the swift class you then simply import it with the following statement: 在swift类中,您只需使用以下语句导入它:

import GoogleAnalytics_iOS_SDK

If this is not working, I think something's wrong in your project settings. 如果这不起作用,我认为你的项目设置有问题。 To fix that, I'll need more info. 要解决这个问题,我需要更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM