简体   繁体   English

iOS Firebase数据库URL

[英]iOS Firebase Database URL

I have been searching the web and gone through all tutorials I found about this subject, read the API reference but ultimately couldn't find any solution to my simple requirement. 我一直在网上搜索并浏览了我发现的关于这个主题的所有教程,阅读了API参考,但最终找不到我的简单要求的任何解决方案。

In iOS / Swift, one has to install a "GoogleService-Info.plist" in the xCode project and then call FIRApp.configure() in the AppDelegate in order to load the configuration from the aforementioned plist file. 在iOS / Swift中,必须在FIRApp.configure()项目中安装“GoogleService-Info.plist”,然后在AppDelegate中调用FIRApp.configure()以从上述plist文件加载配置。

That all works perfectly, but what I would like now is being able to retrieve the parameters from this plist, to be more precise the database URL, so that I don't have to hardcode it anywhere (other than in that plist). 这一切都很完美,但我现在想要的是能够从这个plist中检索参数,更准确地说是数据库URL,这样我就不必在任何地方硬编码(除了那个plist)。

Of course I could use a dictionary to separately read the plist and retrieve the database url, but I would have expected to access the FIRApp object and retrieve it from there... 当然我可以使用字典分别读取plist并检索数据库url,但我本来希望访问FIRApp对象并从那里检索它...

Did I miss something or is that option not given to retrieve the Firebase Parameters / Options directly from the FIRApp Object? 我是否遗漏了某些内容,或者没有直接从FIRApp对象中检索Firebase参数/选项?

您可以使用FIRDatabase.database().reference()来获取通过FIRApp.configure()加载的数据库的引用。

I use a very simple extension ( Swift 4 ): 我使用了一个非常简单的扩展( Swift 4 ):

extension Database {
    var url: URL? {
        let refAsString = "\(FirebaseDatabase.Database.database().reference())"
        return URL(string: refAsString)
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM