Firestore.firestore() 失败并显示“类型‘Firestore’没有成员‘firestore’”

Gle*_*val 5 ios firebase swift google-cloud-firestore

我正在尝试为我的 Firestore 设置数据库,但是我尝试重新安装 Pod 和许多其他东西,但我仍然无法让它工作,因为它显示了以下错误:

Type 'Firestore' has no member 'firebase'
Run Code Online (Sandbox Code Playgroud)

我不知道为什么会这样,因为 Firebase 文档表明这应该是正确的。消息传递部分可以工作,只是以防万一它以某种方式导致错误,请帮助我解决这个问题。

链接到 Firebase > Firestore 文档

这是我的 pod 文件代码:

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
Run Code Online (Sandbox Code Playgroud)

这是我的 AppDelegate 代码:

//
//  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
    }
}
Run Code Online (Sandbox Code Playgroud)

Gay*_*ppu 10

添加以下行

import FirebaseFirestore
Run Code Online (Sandbox Code Playgroud)

在视图控制器的顶部,然后尝试再次构建应用程序。为我工作!

例子:

import FirebaseFirestore
import SwiftUI
import Firebase
import FirebaseDatabase
import Foundation
Run Code Online (Sandbox Code Playgroud)


Gle*_*val 1

这是一个错误,是因为我搞乱了框架并不断安装、卸载、重新安装 Pod,如果发生这种情况,请尝试创建一个新项目,安装所需的所有 Pod,然后从旧项目导入所有代码