【问题标题】:Firestore.firestore() fails with "Type 'Firestore' has no member 'firestore'"Firestore.firestore() 失败并显示“类型‘Firestore’没有成员‘firestore’”
【发布时间】:2018-08-18 21:05:15
【问题描述】:

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

Type 'Firestore' has no member 'firebase'

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

Link to Firebase > Firestore docs

这是我的 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

这是我的 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
    }
}

【问题讨论】:

    标签: ios swift firebase google-cloud-firestore


    【解决方案1】:

    添加以下行

    import FirebaseFirestore
    

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

    示例:

    import FirebaseFirestore
    import SwiftUI
    import Firebase
    import FirebaseDatabase
    import Foundation
    

    【讨论】:

      【解决方案2】:

      问题是你调用了错误的方法,没有名为 Firebase 的成员。而是使用db = Firestore.firestore() 而不是db = Firestore.firebase()。如果这有帮助,请告诉我。

      【讨论】:

      • 对不起,我认为这可能是一个错字,但是我尝试了Firestore.firestore(),它仍然不起作用
      • 很好看的 pho_pho。 @GlebKoval:这绝对是您发布错误的原因。应用修复后错误是否会改变?
      【解决方案3】:

      这是由于我弄乱了框架并不断安装、卸载、重新安装 pod 而导致的错误,如果您遇到这种情况,请尝试创建一个新项目,安装您需要的所有 pod,然后从旧项目

      【讨论】:

      • 没有更好的解决方案吗?
      【解决方案4】:

      我必须将 pod 'Firebase/Firestore' 添加到 podfile 中,然后重新安装。

      【讨论】:

        【解决方案5】:

        这是 xcode 13 中新包管理器的错误。我相信它已在 v13.2.1 中修复

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-01-25
          • 2020-07-26
          • 2023-03-03
          • 1970-01-01
          • 1970-01-01
          • 2021-05-08
          • 2015-01-17
          相关资源
          最近更新 更多