我正在开发一个 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
???
=====再次更新=====
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 - 关于你 appDelegate
在 didFinishLaunchingWithOptions:
添加:
FIRApp.configure()
2 - 在您想获取 firebase 引用的类(class)上,您可以执行以下操作:
let ref = FIRDatabase.database().reference()
这样你就会有ref
对你的 firebase 数据库根目录的引用
关于ios - 无法初始化 Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40562862/