GoogleAnalytics-iOS-SDK on CocoaPods 0.36 with Swift
Anyone knows How do I write Bridging Header for Swift with CocoaPods 0.36?
I tried these ways.
=> this is cocoapods 0.35 style. failed to compile.
=> failed to compile.
=> it can be complied. but failed linking.
- Cocoapods - Unable to find a Specification for
- Why is my library not able to expand on the CocoaPods website?
- Undefined symbols for architecture arm64
- Cocoa Pods Error ld: library not found for -lPods
- Disable bitcode for project and cocoapods dependencies with Xcode7?
- Xcode 7.0.1 - Invalid Swift Support - cocoapods HOW TO FIX?
4 Solutions Collect From Internet About “GoogleAnalytics-iOS-SDK on CocoaPods 0.36 with Swift”
I managed to successfully include Google Analytics iOS SDK 3.10 via Cocoapods into my Swift project using frameworks following these steps.
On the Podfile add (note the
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 section add:
application didFinishLaunchingWithOptions method add:
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).
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
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.
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.
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:
If you’re using pods as frameworks (by setting ‘use_frameworks!’ in your podfile), you don’t need the bridging file. In the swift class you then simply import it with the following statement:
If this is not working, I think something’s wrong in your project settings. To fix that, I’ll need more info.
- How to get the pressed keys in Swift
- How can I tell Asset Catalog (.xcassets) to use the Same Image for Multiple Image Wells?
- Fastest YUV420P to RGBA conversion on iOS using the CPU
- Firebase Commit/Rollback for complex writes
- Upload image from iOS to PHP
- Parse – Subclassing with Swift?
- CTRunGetImageBounds returning inaccurate results
- How to navigate To a ViewController From xib file of a UIView Class
- Xcode 6.4 on OSX 10.11 (El Capitan) beta 2 / beta 3
- UIKit drawing is thread safe: how do you get a graphics context?
- NSLayoutManager hides new line characters no matter what I do
- Objective-C: Find consonants in string
- How to get the image or movie path from the photo Library in swift
- Camera image orientation
- clicking/typing on UITextField increments UIPageViewController instead of displaying keyboard