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

尝试设置对我的Firebase存储的引用,如下所示:

let storage = FIRStorage.storage() 

我看到以下错误:

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

据我所知,一切都设置正确。

  • 我在Firebase上创建并链接了该应用
  • 我已经生成并添加了谷歌plist
  • 我用CocoaPods安装了库:
    • pod’Firebase / Core’
    • pod’Firebase / Storage’

我已经使用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 } 

不确定是否有一些我遗漏的明显事物,从我一直关注的教程中我应该非常直接。 无论哪种方式,任何洞察力将非常感谢! 提前致谢。

其他设置信息:

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

我好像很快就打电话给Firebase。 我将引用调用移到了函数中:

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

一切都运作顺利 – 感谢线索@mgtla!

想要在遵循Firebase教程后发布本文的更新。

applicationDidFinishLaunchingWithOptions有时可能需要更长时间才能运行,并且无法在应用程序的其他区域(即ViewController)运行之前完成代码运行。

因此,您可能会收到“尚未配置默认Firebase应用”等错误。 或者“找不到默认存储桶。您是否正确配置了Firebase存储?” 因为尚未配置Firebase应用

解决方法详细说明了修复此问题的方法。 实质上,您需要将FirebaseApp.configure()语句添加到AppDelegate中的覆盖init()语句,如下所示:

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

希望这可以帮助!

这是根Firebase存储参考:

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