Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
513 views
in Technique[技术] by (71.8m points)

swift3 - How to use Google Analytics for iOS via cocoapods

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: Bridging Header

Build Settings: Build Settings

Podfile: Podfile

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...