【问题标题】:Failed to initialize Firebase无法初始化 Firebase
【发布时间】:2017-03-26 13:30:04
【问题描述】:

我正在开发一个 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() 等)。现在我得到这个错误:

为什么?

我的 Podfile 是这样的:

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

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

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

好的,将'Firebase/Database' 添加到Podfile 解决了上述问题,但是为什么'Firebase' pod 不包含Firebase/Database?不是'Firebase' pod 的子集吗?

【问题讨论】:

标签: ios swift firebase firebase-realtime-database


【解决方案1】:

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

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

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

1 - 在你 appDelegatedidFinishLaunchingWithOptions: 添加:

FIRApp.configure()

2 - 在您想要获取 Firebase 参考的课程上,您可以执行以下操作:

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

这样您将在 ref 上获得对您的 firebase 数据库根目录的引用

【讨论】:

  • 我做了初始化的步骤。当我使用FIRDatabase.database().reference() 时,我收到错误“使用未解析的标识符 FIRDatabase”,为什么?我已经导入了 Firebase。请查看我的更新。
  • 好的,尝试导入 FirebaseDatabase。如果它不起作用,那么添加到您的 Podfile pod 'Firebase/Database'
  • 是的,添加 'Firebase/Database' 到 Podfile 解决了这个问题,但为什么 'Firebase' pod 不包含 'Firebase/Database'?它不是“Firebase”pod 的子集吗?
  • 我认为在他们进行的最后一次更新之后,对 pod 进行了模块化。现在每个特性都有一个 pod,例如:数据库、存储和其他。当您仅添加 Firebase 时,您只会获得其中的配置部分。你能投票给我的答案吗哈哈,我会很感激的。
【解决方案2】:

您需要将您的 iOS 应用添加到 Firebase。如果您还没有这样做,请打开 Firebase 控制台,选择您的项目并添加您的应用,引导初始化。

如果你想使用数据库,你还需要添加Firebase/Database pod ...查看指南https://firebase.google.com/docs/database/ios/start

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-26
    • 2022-01-24
    • 2021-07-27
    • 2020-04-18
    • 2018-05-14
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    相关资源
    最近更新 更多