[英]IOS Swift SwiftUI Firebase “No default Storage bucket found. Did you configure Firebase Storage properly?”
[英]iOS Swift Firebase Storage error “No default Storage bucket found”
在尝试像这样设置对我的 Firebase 存储的引用时:
let storage = FIRStorage.storage()
我看到以下错误:
uncaught exception 'NSInvalidArgumentException', reason: 'No default
Storage bucket found. Did you configure Firebase Storage properly?'
据我所知,一切都设置正确。
我已经使用 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
}
不确定我是否遗漏了一些明显的东西,从我一直在关注的教程来看,这应该非常简单。 无论哪种方式,任何见解都将不胜感激! 提前致谢。
其他设置信息:
看来我过早地调用了 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()
当我将 Firebase Storage 添加到我现有的 iOS 应用程序时,我遇到了这个问题。
您需要重新生成GoogleService-Info.plist
文件,该文件现在将正确包含“STORAGE_BUCKET”键,并在您的项目中更新它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.