我正在尝试为我的 Firestore 设置数据库,但是我尝试重新安装 Pod 和许多其他东西,但我仍然无法让它工作,因为它显示了以下错误:
Type 'Firestore' has no member 'firebase'
我不知道为什么会这样,因为 Firebase 文档表明这应该是正确的。消息传递部分可以工作,只是以防万一它以某种方式导致错误,请帮助我解决这个问题。
链接到 Firebase > Firestore 文档 https://firebase.google.com/docs/firestore/quickstart?authuser=0
这是我的 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
}
}