Use of unresolved identifier GGLContext and GAI

前端 未结 5 843
不知归路
不知归路 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:17

    The only way to make it work for me was downgrade Google Analytics pod version to 2.0.4.

    pod 'Google/Analytics', '~> 2.0.4'

    0 讨论(0)
  • 2021-01-03 20:28

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

    0 讨论(0)
  • 2021-01-03 20:29

    Well, it looks like I was able to get it squared away.

    There were several problems with all attempts on this.

    1. Cocoapods had not installed correctly. I reinstalled and then had better success importing the correct files.

    2. Doing it manually, as I posted above is not the best option.

    3. After the Cocoapods re-install and starting over from a fresh copy of my project, I was able to import Google into my AppDelegate.swift.

    Key points for those who may end up in the same boat I was in:

    • Be sure to add the correct directory for your -Bridging-Header.h. You can find this under Project - Build Settings - Swift Compiler Code Generation. Use this to easily target your header file $(SWIFT_MODULE_NAME)-Bridging-Header.h

    • In your -Bridging-Header.h, do not #import <Google/Analytics.h>, instead import the files individually. Here is an image of the files available to be imported.

    • When in doubt, reinstall Cocoapods

    • Do not trust Google tutorials to provide the most effective instruction and utilize the many SO posts on the topic.

    I really hope this helps someone not spend 10 hours on the problem as I have.

    0 讨论(0)
  • 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 <Google/Analytics.h> 
        #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.

    0 讨论(0)
  • 2021-01-03 20:36

    My error was use of unresolved identifier when i was using the singleton GAI.sharedInstance().

    My steps to bring this to work were:

    1. add pod 'Google/Analytics'
    2. pod install
    3. restart xcode
    4. create a objc class in my project to get a bridging header
    5. added #import "GAI.h" in to the bridging header file

    everything works perfectly.

    0 讨论(0)
提交回复
热议问题