Skip to content

Commit 9919bf0

Browse files
authored
fix(storage, iOS): guard useStorageEmulator to prevent crash on hot restart (#18116)
1 parent 02777d7 commit 9919bf0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/firebase_storage/firebase_storage/ios/firebase_storage/Sources/firebase_storage/FLTFirebaseStoragePlugin.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public final class FLTFirebaseStoragePlugin: NSObject, FlutterPlugin, FirebaseSt
2727
private var handleToTask: [Int64: AnyObject] = [:]
2828
private var handleToPath: [Int64: String] = [:]
2929
private var handleToIdentifier: [Int64: String] = [:]
30+
/// Tracks which buckets have had the emulator set to avoid calling useEmulator more than once
31+
/// per bucket (prevents crash on hot restart). See
32+
/// https://github.com/firebase/flutterfire/pull/11862
33+
private var emulatorBooted: [String: Bool] = [:]
3034

3135
/// Registry to help stream handler classify failure events as cancellations when initiated from
3236
/// Dart
@@ -98,8 +102,13 @@ public final class FLTFirebaseStoragePlugin: NSObject, FlutterPlugin, FirebaseSt
98102

99103
func useStorageEmulator(app: PigeonStorageFirebaseApp, host: String, port: Int64,
100104
completion: @escaping (Result<Void, Error>) -> Void) {
105+
guard emulatorBooted[app.bucket] == nil else {
106+
completion(.success(()))
107+
return
108+
}
101109
let s = storage(app: app)
102110
s.useEmulator(withHost: host, port: Int(port))
111+
emulatorBooted[app.bucket] = true
103112
completion(.success(()))
104113
}
105114

0 commit comments

Comments
 (0)