简体   繁体   English

iOS Swift Firebase 存储错误“未找到默认存储桶”

[英]iOS Swift Firebase Storage error “No default Storage bucket found”

While trying to set a reference to my Firebase Storage like so:在尝试像这样设置对我的 Firebase 存储的引用时:

let storage = FIRStorage.storage()

I am seeing the following error:我看到以下错误:

uncaught exception 'NSInvalidArgumentException', reason: 'No default 
Storage bucket found. Did you configure Firebase Storage properly?'

As far as I know everything is setup properly.据我所知,一切都设置正确。

  • I have created and linked the app on Firebase我已经在 Firebase 上创建并链接了该应用程序
  • I've generated and added the google plist我已经生成并添加了 google plist
  • I have installed the libraries with CocoaPods:我已经用 CocoaPods 安装了这些库:
    • pod 'Firebase/Core'吊舱“Firebase/核心”
    • pod 'Firebase/Storage' pod“Firebase/存储”

I've initialized the app with Firebase with no issues:我已经使用 Firebase 初始化了应用程序,没有任何问题:

import Firebase
import UIKit


class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        // Use Firebase library to configure APIs
        FIRApp.configure()

        return true
    }

Not sure if there is something obvious that I am missing, from the tutorials I've been following this should be pretty straight forward.不确定我是否遗漏了一些明显的东西,从我一直在关注的教程来看,这应该非常简单。 Either way any insight would be much appreciated!无论哪种方式,任何见解都将不胜感激! Thanks in advance.提前致谢。

Other setup info:其他设置信息:

  • Xcode Version: 8.2.1 Xcode 版本:8.2.1
  • CocoaPods Version: 1.2.1 CocoaPods 版本:1.2.1

It seems I was calling on Firebase too soon.看来我过早地调用了 Firebase。 I moved the reference call into the function:我将引用调用移动到函数中:

func uploadToFirebase(data: Data) {
    let ref = FIRStorage.storage().reference(withPath: "images/demoPic.jpg")
   ...
}

And everything has been working smoothly - thanks for the clue @mgtla !一切都在顺利进行——感谢@mgtla 提供线索!

Wanted to post an update for others finding this article after following a Firebase Tutorial.希望在遵循 Firebase 教程后为其他发现本文的人发布更新。

The applicationDidFinishLaunchingWithOptions can sometimes take longer to run, and will not finish running prior to code in other areas of your app (ie the ViewController) running. applicationDidFinishLaunchingWithOptions 有时可能需要更长的时间才能运行,并且不会在应用程序其他区域(即 ViewController)中的代码运行之前完成运行。

Therefore, you may get errors like "The default Firebase app has not yet been configured."因此,您可能会收到诸如“尚未配置默认 Firebase 应用”之类的错误消息。 or "No default Storage bucket found. Did you configure Firebase Storage properly?"或“未找到默认存储桶。您是否正确配置了 Firebase 存储?” because the Firebase app hasn't yet been configured .因为Firebase 应用尚未配置

The way to fix this is detailed in this answer. 这个答案详细说明了解决这个问题的方法。 Essentially, you need to add the FirebaseApp.configure() statement to an override init() statement in your AppDelegate like this:本质上,您需要将 FirebaseApp.configure() 语句添加到 AppDelegate 中的覆盖 init() 语句中,如下所示:

override init() {
   super.init()
   FIRApp.configure()
   // not really needed unless you really need it FIRDatabase.database().persistenceEnabled = true
}

Hope this helps!希望这可以帮助!

这是根 Firebase 存储参考:

let storageRef = FIRStorage.storage().reference()

I ran into this issue when I added Firebase Storage to my existing iOS app.当我将 Firebase Storage 添加到我现有的 iOS 应用程序时,我遇到了这个问题。

You'll need to re-generate the GoogleService-Info.plist file, which will now correctly include the "STORAGE_BUCKET" key, and update it within your project.您需要重新生成GoogleService-Info.plist文件,该文件现在将正确包含“STORAGE_BUCKET”键,并在您的项目中更新它。

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

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