Use of unresolved identifier GGLContext and GAI

前端 未结 5 845
不知归路
不知归路 2021-01-03 20:00

I am having a bit of trouble. I am attempting to install Google Analytics into an app and am consistently getting the use of unresolved identifier GGLContext a

5条回答
  •  鱼传尺愫
    2021-01-03 20:35

    This works for swift 2.3, swift 3.0 and swift 4:

    1. add the GoogleService-Info.plist file to the root of your project
    2. add this to the podfile:

        pod 'Google/Analytics'
      
    3. quit Xcode, run "pod install" in terminal and open Xcode again
    4. create a header file in the project root, named Bridging-Header.h, under build settings make sure the bridging header is defined like in the picture

    5. make sure your Bridging-Header.h looks like this:

        #ifndef Bridging_Header_h
        #define Bridging_Header_h
        #import  
        #endif /* Bridging_Header_h */
      
    6. add to AppDelegate:

      import Google        
      
    7. add this code to AppDelegate in the didFinishLaunchingWithOptions method:

      // Configure tracker from GoogleService-Info.plist.
      var configureError: NSError?
      GGLContext.sharedInstance().configureWithError(&configureError)
      
      assert(configureError == nil, "Error configuring Google services:\(configureError)")
      
      // Optional: configure GAI options.
      guard let gai = GAI.sharedInstance() else {
          assert(false, "Google Analytics not configured correctly")
      }
      gai.trackUncaughtExceptions = true  // report uncaught exceptions
      gai.logger.logLevel = GAILogLevel.Verbose  // remove before app release
      

    If there are errors, deleting DerivedData and cleaning the project can help.

提交回复
热议问题