Firestore.firestore()失败了" Type' Firestore'没有会员' firestore'"

时间:2018-03-10 10:52:55

标签: ios swift firebase google-cloud-firestore

我正在尝试为我的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
    }
}

4 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

这是一个错误,是因为我弄乱了框架并保持安装,卸载,重新安装pod,如果你碰巧尝试制作一个新项目,安装所需的所有pod,然后导入所有代码旧项目

答案 2 :(得分:1)

我必须将pod 'Firebase/Firestore'添加到Podfile中,然后再次安装。

答案 3 :(得分:0)

添加以下行

import FirebaseFirestore
在视图控制器顶部的

,然后尝试再次构建应用。为我工作!

示例:

import FirebaseFirestore
import SwiftUI
import Firebase
import FirebaseDatabase
import Foundation