简体   繁体   中英

iOS Swift Firebase Storage error “No default Storage bucket found”

While trying to set a reference to my Firebase Storage like so:

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
  • I've generated and added the google plist
  • I have installed the libraries with CocoaPods:
    • pod 'Firebase/Core'
    • pod 'Firebase/Storage'

I've initialized the app with Firebase with no issues:

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
  • CocoaPods Version: 1.2.1

It seems I was calling on Firebase too soon. 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 !

Wanted to post an update for others finding this article after following a Firebase Tutorial.

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.

Therefore, you may get errors like "The default Firebase app has not yet been configured." or "No default Storage bucket found. Did you configure Firebase Storage properly?" because the Firebase app hasn't yet been configured .

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:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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