Anyone knows How do I write Bridging Header for Swift with CocoaPods 0.36?
I tried these ways.
(1)
#import <GoogleAnalytics-iOS-SDK/GAI.h>
=> this is cocoapods 0.35 style. failed to compile.
(2)
#import <GoogleAnalytics-iOS-SDK/GoogleAnalytics-iOS-SDK/GAI.h>
=> failed to compile.
(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.
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
On the AppDelegate
import section add:
import GoogleAnalytics_iOS_SDK
On the 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).
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
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.
I had a similar problem on CocoaPods 0.39.0.
$(inherited) in build setting 'OTHER_LDFLAGS' solved it.
https://stackoverflow.com/a/32004207/3129306
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With