问题
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'
回答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.
来源:https://stackoverflow.com/questions/49093139/pod-googleanalytics-in-swift-4-wont-run