5

I am trying to setup a database for my Firestore however I tried reinstalling the pods and many other things and I still cannot get it to work because it shows this error:

Type 'Firestore' has no member 'firebase'

I do not know why that is as the Firebase docs show that this should be correct. The messaging part work, it's just there just in case it is causing the error somehow, please help me to solve this.

Link to Firebase > Firestore docs

This is my pod file code:

project 'Pocket Games.xcodeproj'
platform :ios, '10.0'

target 'Pocket Games' do
  use_frameworks!

  pod 'Google-Mobile-Ads-SDK'

  pod 'Firebase/Core'

  pod 'Firebase/Messaging'

  pod 'Firebase/Auth'

  pod 'Firebase/Firestore'

  pod 'Canvas'
end

and this is my AppDelegate code:

//
//  AppDelegate.swift

import UIKit
import CoreData
import UserNotifications
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?



    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        FirebaseApp.configure()

        let db = Firestore.firestore()  // <- This is the line that doesn't work and comes up with "Type 'Firestore' has no member 'firebase'"

        // Firebase cloud messanging
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound], completionHandler: {(success, error) in
            if error == nil {
                print("notifications successful")
                if CoreData.shared.saveData(entity: "Notifications", entitySub: ["games_updates","new_apps_from_developer","new_games","updates"], content: ["true","true","true","false"]) {
                    print("Notification CoreData setup successful")
                }
            }
        })
        application.registerForRemoteNotifications()
        NotificationCenter.default.addObserver(self, selector: #selector(self.refreshTocken(_:)), name: NSNotification.Name.InstanceIDTokenRefresh, object: nil)
        //-----------------------------


        return true
    }


    func applicationDidEnterBackground(_ application: UIApplication) {
        Messaging.messaging().shouldEstablishDirectChannel = false
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        FireBaseHandler()
    }
    func applicationWillTerminate(_ application: UIApplication) {

    }


    // MARK: - FireBase remote messanging


    @objc func refreshTocken(_ notification: NSNotification) {
        let refreshTocken = InstanceID.instanceID().token()
        print("\n***\n\(String(describing: refreshTocken))\n***\n")
        FireBaseHandler()
    }
    func FireBaseHandler() {
        Messaging.messaging().shouldEstablishDirectChannel = true
    }
}
Gleb Koval
  • 149
  • 1
  • 10

5 Answers5

10

Add following line

import FirebaseFirestore

at the top of the view controller and try building the app again. Worked for me!

Example:

import FirebaseFirestore
import SwiftUI
import Firebase
import FirebaseDatabase
import Foundation
Gayal Kuruppu
  • 1,261
  • 1
  • 17
  • 29
4

The problem is that you are calling the wrong method, there is no member called Firebase. Instead use db = Firestore.firestore() not db = Firestore.firebase(). Please let me know if this helps.

pho_pho
  • 672
  • 11
  • 30
1

This was an error that was caused because of me messing up the frameworks and keeping installing, uninstalling, reinstalling pods, if this happens to you try making a new project, installing all the pods you need and then import all the code from the old project

Gleb Koval
  • 149
  • 1
  • 10
1

I had to add pod 'Firebase/Firestore' to the podfile and then install it again.

Pseudonym Patel
  • 469
  • 7
  • 16
0

This is a bug with the new package manager in xcode 13. I believe it was fixed in v13.2.1