Skip to content

Commit

Permalink
fix(storage, apple): set the storage emulator only once to stop it fr…
Browse files Browse the repository at this point in the history
…om crashing on hot restart (#11862)
  • Loading branch information
russellwheatley authored Nov 14, 2023
1 parent 963c1b8 commit 7f07d7a
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ @interface FLTFirebaseStoragePlugin ()
@implementation FLTFirebaseStoragePlugin {
NSMutableDictionary<NSNumber *, FIRStorageObservableTask<FIRStorageTaskManagement> *> *_tasks;
dispatch_queue_t _callbackQueue;
bool hasEmulatorBooted;
NSMutableDictionary<NSString *, NSNumber *> *_emulatorBooted;
NSObject<FlutterBinaryMessenger> *_binaryMessenger;
NSMutableDictionary<NSString *, FlutterEventChannel *> *_eventChannels;
NSMutableDictionary<NSString *, NSObject<FlutterStreamHandler> *> *_streamHandlers;
Expand Down Expand Up @@ -97,7 +97,7 @@ - (instancetype)init:(NSObject<FlutterBinaryMessenger> *)messenger {
dictionary];
_callbackQueue =
dispatch_queue_create("io.flutter.plugins.firebase.storage", DISPATCH_QUEUE_SERIAL);
hasEmulatorBooted = false;
_emulatorBooted = [[NSMutableDictionary alloc] init];
_binaryMessenger = messenger;
_eventChannels = [NSMutableDictionary dictionary];
_streamHandlers = [NSMutableDictionary dictionary];
Expand Down Expand Up @@ -242,7 +242,12 @@ - (void)useStorageEmulatorApp:(PigeonStorageFirebaseApp *)app
port:(NSNumber *)port
completion:(void (^)(FlutterError *_Nullable))completion {
FIRStorage *storage = [self getFIRStorageFromAppNameFromPigeon:app];
[storage useEmulatorWithHost:host port:[port integerValue]];
NSNumber *emulatorKey = _emulatorBooted[app.bucket];

if (emulatorKey == nil) {
[storage useEmulatorWithHost:host port:[port integerValue]];
[_emulatorBooted setObject:@(YES) forKey:app.bucket];
}
completion(nil);
}

Expand Down

0 comments on commit 7f07d7a

Please sign in to comment.