pod 'GoogleAnalytics' in swift 4 won't run
Asked Answered
M

1

1

I read this instructions to use google analytics in my app https://developers.google.com/analytics/devguides/collection/ios/v3/?ver=swift so I installed pod 'GoogleAnalytics' into my app and created a .h file in my swift application so here is my h file codes in my app

#ifndef analytic_h
#define analytic_h
#import <Google/Analytics.h>

#endif /* analytic_h */

and here is my app Delegate codes But this code does not recognize GAI

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    guard let gai = GAI.sharedInstance() else {
        assert(false, "Google Analytics not configured correctly")
    }
    gai.tracker(withTrackingId: "UA-xxxxxxxxx-x")
    // Optional: automatically report uncaught exceptions.
    gai.trackUncaughtExceptions = true

    // Optional: set Logger to VERBOSE for debug information.
    // Remove before app release.
    gai.logger.logLevel = .verbose;

    return true
}

I received this error for GAI

Use of unresolved identifier 'GAI'

Milena answered 4/3, 2018 at 7:42 Comment(2)
In my app, I'm importing the specific .h file like this: #import "GAI.h"Koeninger
I have this file because the googleAnalytics pod file has been installed But again I am receiving this error in AppDelegateMilena
S
1

My research on this-

Case 1- Adding Bridging header manually

I added .h file with name "MyProject-Bridging-Header.h" in the project. And I received a file having content-

#ifndef MyProject-Bridging-Header_h
#define MyProject-Bridging-Header_h


#endif /* MyProject-Bridging-Header_h */

And then I tried adding one of the followings-

#import <GAI.h>
#import <Google/Analytics.h>

But none of them were working.

Case 2 - Adding bridging header automatically

For this, I added "Objective-C File" and it gave a prompt to add bridging header automatically and I accepted. In that bridging header file, I added

 #import <GAI.h>

then it built like a charm and after that, I removed the line above and added -

#import <Google/Analytics.h>

It failed saying Google/Analytics.h not found.

Sleeper answered 4/3, 2018 at 11:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.