Skip to content

Commit efd1f45

Browse files
committed
Updated calling setStorageURL automatically when using configuration options
1 parent ee5c891 commit efd1f45

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ firestack.setStorageUrl(`gs://${config.firebase.storageBucket}`)
364364
.catch(() => console.error('This is weird: something happened...'))
365365
```
366366

367+
If the `storageBucket` key is passed as a configuration option, this method is automatically called for us by default.
368+
367369
#### uploadFile()
368370

369371
We can upload a file using the `uploadFile()` method. Using the `uploadFile()` method, we can set the name of the destination file, the path where we want to store it, as well as any metadata along with the file.

ios/Firestack/Firestack.m

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ @implementation Firestack
2020

2121
FIROptions *firestackOptions = [FIROptions defaultOptions];
2222
// Bundle ID either from options OR from the main bundle
23-
NSString *bundleID = [firestackOptions valueForKey:@"bundleID"];
23+
NSString *bundleID;
2424
if ([opts valueForKey:@"bundleID"]) {
2525
bundleID = [opts valueForKey:@"bundleID"];
2626
} else {
27-
if (bundleID == nil) {
28-
bundleID = [[NSBundle mainBundle] bundleIdentifier];
29-
}
27+
bundleID = [[NSBundle mainBundle] bundleIdentifier];
3028
}
3129
// Prefer the user configuration options over the default options
3230
NSArray *keyOptions = @[@"APIKey", @"clientID", @"trackingID",
@@ -52,11 +50,6 @@ @implementation Firestack
5250
}
5351
}
5452

55-
for (NSString *key in props) {
56-
[self debugLog:key msg:[props valueForKey:key]];
57-
}
58-
[self debugLog:@"bundleID" msg:bundleID];
59-
6053
@try {
6154
FIROptions *finalOptions = [[FIROptions alloc] initWithGoogleAppID:[props valueForKey:@"googleAppID"]
6255
bundleID:bundleID
@@ -68,8 +61,19 @@ @implementation Firestack
6861
databaseURL:[props valueForKey:@"databaseURL"]
6962
storageBucket:[props valueForKey:@"storageBucket"]
7063
deepLinkURLScheme:[props valueForKey:@"deepLinkURLScheme"]];
64+
65+
for (NSString *key in props) {
66+
[self debugLog:key msg:[finalOptions valueForKey:key]];
67+
}
68+
[self debugLog:@"bundleID" msg:bundleID];
69+
7170
if (!self.configured) {
7271
[FIRApp configureWithOptions:finalOptions];
72+
73+
if ([props valueForKey:@"storageBucket"]) {
74+
[self setStorageUrl:[NSString stringWithFormat:@"gs://%@", [props valueForKey:@"storageBucket"]]
75+
callback:nil];
76+
}
7377
self->_configured = YES;
7478
}
7579
callback(@[[NSNull null]]);
@@ -416,10 +420,12 @@ @implementation Firestack
416420
}
417421

418422
[storageConfig setValue:name forKey:@"url"];
419-
420423
[cfg setObject:storageConfig forKey:@"storage"];
421424

422425
self.configuration = cfg;
426+
if (callback != nil) {
427+
callback(@[[NSNull null], self.configuration]);
428+
}
423429
}
424430

425431
RCT_EXPORT_METHOD(uploadFile:(NSString *) name

0 commit comments

Comments
 (0)