Firestore.firestore()失败,并显示“类型'Firestore'没有成员'firestore'". [英] Firestore.firestore() fails with "Type 'Firestore' has no member 'firestore'"

查看:55
本文介绍了Firestore.firestore()失败,并显示“类型'Firestore'没有成员'firestore'".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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'

我不知道为什么这样做,因为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.

链接到Firebase> Firestore文档

这是我的pod文件代码:

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

这是我的AppDelegate代码:

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
    }
}

推荐答案

这是由于我弄乱了框架并继续安装,卸载和重新安装Pod而导致的错误,如果您碰巧遇到这种情况,请尝试创建一个新项目,安装所需的所有Pod,然后从旧项目中导入所有代码

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

这篇关于Firestore.firestore()失败,并显示“类型'Firestore'没有成员'firestore'".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆