ios - 无法初始化 Firebase

标签 ios swift firebase firebase-realtime-database

我正在开发一个 iOS 项目(使用 xcode 8 和 swift 3)。我已经通过 cocoapod 安装了 firebase pod。这是我的播客:

target 'myApp' do
   pod 'Firebase', '~> 3.9'
end

然后我打开 myApp.xcworkspace 文件,项目在 Xcode 中打开。

然后我尝试通过以下方式初始化一个 firebase 实例:

let BASE_URL = "https://myapp-35211.firebaseio.com/"
// ERROR: Cannot call value of non-function type 'module<Firebase>'
let firebase = Firebase(url: "\(BASE_URL)")

(我有import Firebase)

我正在尝试使用 firebase 数据库。

为什么会出现上述错误?

======更新=======

好的,我按照步骤初始化 Firebase(在 Firebase 中添加我的项目,下载 GoogleService-Info.plist 并使用 FIRApp.configure() 等)。现在我得到这个错误:

enter image description here

为什么?

我的 Podfile 是这样的:

target 'myApp' do
   pod 'Firebase', '~> 3.9'
end

这是否意味着此 pod 不包含 Firebase/Database ???

=====再次更新=====

OK,在Podfile中添加'Firebase/Database'解决了上述问题,但是为什么'Firebase' pod不包含Firebase/数据库?它不是 'Firebase' pod 的子集吗?

最佳答案

我不确定您为什么要在代码中使用基本 url,因为现在,当您设置 firebase 项目时,您可以通过 Bundle identifier 将您的应用程序项目与 firebase 项目链接起来。 .

查看 Firebase 文档:https://firebase.google.com/docs/database/ios/start

如果你这样做,那么你只需要做2个步骤:

1 - 关于你 appDelegatedidFinishLaunchingWithOptions:添加:

FIRApp.configure()

2 - 在您想获取 firebase 引用的类(class)上,您可以执行以下操作:

let ref = FIRDatabase.database().reference()

这样你就会有ref对你的 firebase 数据库根目录的引用

关于ios - 无法初始化 Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40562862/

相关文章:

ios - 带有 Firebase Id token 的 Firestore REST API

ios - 在 UITextField swift 3.0 中使用数字键盘以 dd-MM-yyyy 格式输入日期

ios - 在 Xcode 中的两个坐标之间绘制多段线

ios - 当快速弹出日期选择器选择器时,如何阻止 ui 对象被覆盖

ios - 使用 dataTask 在 func 上快速显示和隐藏事件指示器

php - 在登录检查 PHP 和 SWIFT 时抛出相同的响应

android - 有什么方法可以在 Firebase 崩溃报告中设置键值对吗?

javascript - 我正在尝试将使用过的 UID 添加到实时数据库中?

ios - 如何使用循环在行中仅显示 3 个按钮,在列中仅显示一个按钮

ios - ios中UITabBarController中的UITabBarController使用 Storyboard