Type 'Analytics' has no member 'logEvent' Xcode

26 Views Asked by At

Had a problem, when tried to implement Analytics into my project on Xcode:

Analytics.logEvent(AnalyticsEventSelectContent, parameters: [
    AnalyticsParameterItemID: "id-\(testTitle)",
    AnalyticsParameterItemName: testTitle,
    AnalyticsParameterContentType: "cont",
])

Error: Cannot find 'Analytics' in scope and Cannot find 'AnalyticsParameterItemName' in scope.

Script: import FirebaseStorage

class mainScreenScript: UIViewController
{

override func viewDidLoad()
    {
        super.viewDidLoad()

        let testTitle = "TestContentTitle"

        Analytics.logEvent(AnalyticsEventSelectContent, parameters: [
            AnalyticsParameterItemID: "id-\(testTitle)",
            AnalyticsParameterItemName: testTitle,
            AnalyticsParameterContentType: "cont",
        ])
    }
}

My pods were:

platform :ios, '13.0'

target '(myAppName)' do
  use_frameworks!

  # Pods for (myAppName)
  
  pod 'Firebase/Auth'
  pod 'Firebase/Firestore'
  pod 'FirebaseUI'
  pod 'FirebaseAnalytics'
  pod 'FirebaseUI/Email'
  pod 'Firebase/Storage', '~> 8.0'
  pod 'GoogleUtilities/UserDefaults'
  pod 'Charts'
  pod 'IQKeyboardManagerSwift'
  pod 'CryptoSwift'
  pod 'Firebase/MLModelDownloader'
  pod 'TensorFlowLiteSwift'
  pod 'GoogleSignIn'
  pod 'FBSDKLoginKit'
  pod 'FBSDKCoreKit'
  pod 'Google-Mobile-Ads-SDK'
  pod 'SideMenu'
  pod "MBCircularProgressBar"
  pod 'DGCharts' 


end


post_install do |installer|
    installer.generated_projects.each do |project|
          project.targets.each do |target|
              target.build_configurations.each do |config|
                  config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
               end
          end
   end
end

AppDelegate:

import Firebase
import FirebaseFirestore
import FirebaseAuthUI
import FirebaseStorage

and

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
    FirebaseApp.configure()
    let db = Firestore.firestore()
    
    //other parts of the code
    
    ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
    
    return true
}
1

There are 1 best solutions below

0
Mr.Schtelbe On

Had to change AppDelegate to:

import FirebaseCore

Added to pods:

pod 'FirebaseAnalytics'

Then updated my pods (pod update) So I got:

Downloading dependencies
Installing CryptoSwift 1.8.1 (was 1.7.1)
Installing FBAEMKit 16.3.1 (was 15.1.0)
Installing FBSDKCoreKit 16.3.1 (was 15.1.0)
Installing FBSDKCoreKit_Basics 16.3.1 (was 15.1.0)
Installing FBSDKLoginKit 16.3.1 (was 15.1.0)
Installing FirebaseAnalytics 8.15.0 (was 3.4.2)
Installing FirebaseAnonymousAuthUI 13.1.0 (was 13.0.0)
Installing FirebaseAuthUI 13.1.0 (was 13.0.0)
Installing FirebaseDatabaseUI 13.1.0 (was 13.0.0)
Installing FirebaseEmailAuthUI 13.1.0 (was 13.0.0)
Installing FirebaseFacebookAuthUI 13.1.0 (was 13.0.0)
Installing FirebaseFirestoreUI 13.1.0 (was 13.0.0)
Installing FirebaseGoogleAuthUI 13.1.0 (was 13.0.0)
Installing FirebaseOAuthUI 13.1.0 (was 13.0.0)
Installing FirebasePhoneAuthUI 13.1.0 (was 13.0.0)
Installing FirebaseStorageUI 13.1.0 (was 13.0.0)
Installing FirebaseUI 13.1.0 (was 13.0.0)
Installing Google-Mobile-Ads-SDK 11.0.0 (was 10.12.0)
Installing GoogleAppMeasurement 8.15.0 (was 10.16.0)
Installing GoogleDataTransport 9.3.0 (was 9.2.3)
Installing GoogleUtilities 7.12.0 (was 1.3.2)
Installing IQKeyboardManagerSwift 7.0.1 (was 6.5.11)
Installing PromisesObjC 2.3.1 (was 2.2.0)
Installing SDWebImage 5.18.10 (was 5.15.7)
Installing SwiftProtobuf 1.25.2 (was 1.21.0)
Installing TensorFlowLiteC 2.14.0 (was 2.12.0)
Installing TensorFlowLiteSwift 2.14.0 (was 2.12.0)
Installing leveldb-library 1.22.3 (was 1.22.2)
Removing FirebaseInstanceID
Removing GoogleInterchangeUtilities
Removing GoogleSymbolUtilities
Generating Pods project
Integrating client project
Pod installation complete! There are 19 dependencies from the Podfile and 53 total pods installed.

P.S. I had some pods, that you might not need.

The next step was to clean the Build folder (Cmd + Shift + K) - for those, who dont know.

After this was able to build and run.