@@ -17,7 +17,7 @@ @implementation Firestack
17
17
{
18
18
// Are we debugging, yo?
19
19
self.debug = [opts valueForKey: @" debug" ] != nil ? YES : NO ;
20
-
20
+
21
21
FIROptions *firestackOptions = [FIROptions defaultOptions ];
22
22
// Bundle ID either from options OR from the main bundle
23
23
NSString *bundleID;
@@ -31,7 +31,7 @@ @implementation Firestack
31
31
@" GCMSenderID" , @" androidClientID" ,
32
32
@" googleAppID" , @" databaseURL" ,
33
33
@" deepLinkURLScheme" , @" storageBucket" ];
34
-
34
+
35
35
NSMutableDictionary *props = [[NSMutableDictionary alloc ] initWithCapacity: [keyOptions count ]];
36
36
for (int i=0 ; i < [keyOptions count ]; i++) {
37
37
// Traditional for loop here
@@ -49,7 +49,7 @@ @implementation Firestack
49
49
NSLog (@" An error occurred: %@ " , err);
50
50
}
51
51
}
52
-
52
+
53
53
@try {
54
54
FIROptions *finalOptions = [[FIROptions alloc ] initWithGoogleAppID: [props valueForKey: @" googleAppID" ]
55
55
bundleID: bundleID
@@ -61,16 +61,16 @@ @implementation Firestack
61
61
databaseURL: [props valueForKey: @" databaseURL" ]
62
62
storageBucket: [props valueForKey: @" storageBucket" ]
63
63
deepLinkURLScheme: [props valueForKey: @" deepLinkURLScheme" ]];
64
-
64
+
65
65
for (NSString *key in props) {
66
66
[self debugLog: key msg: [finalOptions valueForKey: key]];
67
67
}
68
68
[self debugLog: @" bundleID" msg: bundleID];
69
-
69
+
70
70
// Save configuration option
71
71
NSDictionary *cfg = [self getConfig ];
72
72
[cfg setValuesForKeysWithDictionary: props];
73
-
73
+
74
74
if (!self.configured ) {
75
75
[FIRApp configureWithOptions: finalOptions];
76
76
self->_configured = YES ;
@@ -111,9 +111,9 @@ @implementation Firestack
111
111
};
112
112
return callback (@[err]);
113
113
}
114
-
114
+
115
115
NSLog (@" signinWithCredential: %@ " , credential);
116
-
116
+
117
117
@try {
118
118
[[FIRAuth auth ] signInWithCredential: credential
119
119
completion: ^(FIRUser *user, NSError *error) {
@@ -159,7 +159,7 @@ @implementation Firestack
159
159
{
160
160
self->authListenerHandle = [[FIRAuth auth ] addAuthStateDidChangeListener: ^(FIRAuth *_Nonnull auth,
161
161
FIRUser *_Nullable user) {
162
-
162
+
163
163
if (user != nil ) {
164
164
// User is signed in.
165
165
NSDictionary *userProps = [self userPropsFromFIRUser: user];
@@ -195,7 +195,7 @@ @implementation Firestack
195
195
RCT_EXPORT_METHOD (getCurrentUser:(RCTResponseSenderBlock)callback)
196
196
{
197
197
FIRUser *user = [FIRAuth auth ].currentUser ;
198
-
198
+
199
199
if (user != nil ) {
200
200
NSDictionary *userProps = [self userPropsFromFIRUser: user];
201
201
callback (@[[NSNull null ], userProps]);
@@ -255,7 +255,7 @@ @implementation Firestack
255
255
callback:(RCTResponseSenderBlock) callback)
256
256
{
257
257
FIRUser *user = [FIRAuth auth ].currentUser ;
258
-
258
+
259
259
[user updateEmail: email completion: ^(NSError *_Nullable error) {
260
260
if (error) {
261
261
// An error happened.
@@ -275,9 +275,9 @@ @implementation Firestack
275
275
RCT_EXPORT_METHOD (updateUserPassword:(NSString *)newPassword
276
276
callback:(RCTResponseSenderBlock) callback)
277
277
{
278
-
278
+
279
279
FIRUser *user = [FIRAuth auth ].currentUser ;
280
-
280
+
281
281
[user updatePassword: newPassword completion: ^(NSError *_Nullable error) {
282
282
if (error) {
283
283
// An error happened.
@@ -297,7 +297,7 @@ @implementation Firestack
297
297
RCT_EXPORT_METHOD (sendPasswordResetWithEmail:(NSString *)email
298
298
callback:(RCTResponseSenderBlock) callback)
299
299
{
300
-
300
+
301
301
[[FIRAuth auth ] sendPasswordResetWithEmail: email
302
302
completion: ^(NSError *_Nullable error) {
303
303
if (error) {
@@ -319,7 +319,7 @@ @implementation Firestack
319
319
RCT_EXPORT_METHOD (deleteUser:(RCTResponseSenderBlock) callback)
320
320
{
321
321
FIRUser *user = [FIRAuth auth ].currentUser ;
322
-
322
+
323
323
[user deleteWithCompletion: ^(NSError *_Nullable error) {
324
324
if (error) {
325
325
NSDictionary *err =
@@ -348,9 +348,9 @@ @implementation Firestack
348
348
};
349
349
return callback (@[err]);
350
350
}
351
-
351
+
352
352
FIRUser *user = [FIRAuth auth ].currentUser ;
353
-
353
+
354
354
[user reauthenticateWithCredential: credential completion: ^(NSError *_Nullable error) {
355
355
if (error) {
356
356
NSDictionary *err =
@@ -370,7 +370,7 @@ @implementation Firestack
370
370
{
371
371
FIRUser *user = [FIRAuth auth ].currentUser ;
372
372
FIRUserProfileChangeRequest *changeRequest = [user profileChangeRequest ];
373
-
373
+
374
374
NSMutableArray *allKeys = [[userProps allKeys ] mutableCopy ];
375
375
for (NSString *key in allKeys) {
376
376
// i.e. changeRequest.displayName = userProps[displayName];
@@ -429,23 +429,23 @@ - (NSString *) getStorageUrl
429
429
callback:(RCTResponseSenderBlock) callback)
430
430
{
431
431
NSDictionary *cfg = [self getConfig ];
432
-
432
+
433
433
NSString *urlStr = [self getStorageUrl ];
434
-
434
+
435
435
if (urlStr == nil ) {
436
436
NSError *err = [[NSError alloc ] init ];
437
437
[err setValue: @" Storage configuration error" forKey: @" name" ];
438
438
[err setValue: @" Call setStorageUrl() first" forKey: @" description" ];
439
439
return callback (@[err]);
440
440
}
441
-
441
+
442
442
FIRStorageReference *storageRef = [[FIRStorage storage ] referenceForURL: urlStr];
443
443
FIRStorageReference *uploadRef = [storageRef child: name];
444
-
444
+
445
445
NSURL *localFile = [NSURL fileURLWithPath: path];
446
-
446
+
447
447
FIRStorageMetadata *firmetadata = [[FIRStorageMetadata alloc ] initWithDictionary: metadata];
448
-
448
+
449
449
FIRStorageUploadTask *uploadTask = [uploadRef putFile: localFile
450
450
metadata: firmetadata];
451
451
// Listen for state changes, errors, and completion of the upload.
@@ -455,7 +455,7 @@ - (NSString *) getStorageUrl
455
455
@" ref" : snapshot.reference .bucket
456
456
}];
457
457
}];
458
-
458
+
459
459
[uploadTask observeStatus: FIRStorageTaskStatusPause handler: ^(FIRStorageTaskSnapshot *snapshot) {
460
460
// Upload paused
461
461
[self sendJSEvent: @" uploadPaused" props: @{
@@ -465,13 +465,13 @@ - (NSString *) getStorageUrl
465
465
[uploadTask observeStatus: FIRStorageTaskStatusProgress handler: ^(FIRStorageTaskSnapshot *snapshot) {
466
466
// Upload reported progress
467
467
double percentComplete = 100.0 * (snapshot.progress .completedUnitCount ) / (snapshot.progress .totalUnitCount );
468
-
468
+
469
469
[self sendJSEvent: @" uploadProgress" props: @{
470
470
@" progress" : @(percentComplete || 0.0 )
471
471
}];
472
-
472
+
473
473
}];
474
-
474
+
475
475
[uploadTask observeStatus: FIRStorageTaskStatusSuccess handler: ^(FIRStorageTaskSnapshot *snapshot) {
476
476
// Upload completed successfully
477
477
FIRStorageReference *ref = snapshot.reference ;
@@ -481,10 +481,10 @@ - (NSString *) getStorageUrl
481
481
@" name" : ref.name ,
482
482
@" metadata" : [snapshot.metadata dictionaryRepresentation ]
483
483
};
484
-
484
+
485
485
callback (@[[NSNull null ], props]);
486
486
}];
487
-
487
+
488
488
[uploadTask observeStatus: FIRStorageTaskStatusFailure handler: ^(FIRStorageTaskSnapshot *snapshot) {
489
489
if (snapshot.error != nil ) {
490
490
NSError *err = [[NSError alloc ] init ];
@@ -506,7 +506,7 @@ - (NSString *) getStorageUrl
506
506
[err setValue: @" Unknown error" forKey: @" description" ];
507
507
break ;
508
508
}
509
-
509
+
510
510
callback (@[err]);
511
511
}}];
512
512
}
@@ -520,7 +520,7 @@ - (NSString *) getStorageUrl
520
520
// Create remote Config instance
521
521
self.remoteConfigInstance = [FIRRemoteConfig remoteConfig ];
522
522
}
523
-
523
+
524
524
[self .remoteConfigInstance setDefaults: props];
525
525
callback (@[[NSNull null ], props]);
526
526
}
@@ -542,10 +542,15 @@ - (NSString *) getStorageUrl
542
542
};
543
543
callback (@[err]);
544
544
}
545
-
546
-
545
+
546
+
547
547
FIRRemoteConfigValue *value = [self .remoteConfigInstance configValueForKey: name];
548
- callback (@[[NSNull null ], value.stringValue]);
548
+ NSString *valueStr = value.stringValue ;
549
+
550
+ if (valueStr == nil ) {
551
+ valueStr = @" " ;
552
+ }
553
+ callback (@[[NSNull null ], valueStr]);
549
554
}
550
555
551
556
RCT_EXPORT_METHOD (fetchWithExpiration:(NSNumber *)expirationSeconds
@@ -558,22 +563,22 @@ - (NSString *) getStorageUrl
558
563
};
559
564
callback (@[err]);
560
565
}
561
-
566
+
562
567
NSTimeInterval expirationDuration = [expirationSeconds doubleValue ];
563
-
568
+
564
569
[self .remoteConfigInstance fetchWithExpirationDuration: expirationDuration completionHandler: ^(FIRRemoteConfigFetchStatus status, NSError *error) {
565
570
if (status == FIRRemoteConfigFetchStatusSuccess) {
566
571
NSLog (@" Config fetched!" );
567
572
[self .remoteConfigInstance activateFetched ];
568
573
callback (@[[NSNull null ], @(YES )]);
569
574
} else {
570
575
NSLog (@" Error %@ " , error.localizedDescription );
571
-
576
+
572
577
NSDictionary *err = @{
573
578
@" error" : @" No configuration instance" ,
574
579
@" msg" : [error localizedDescription ]
575
580
};
576
-
581
+
577
582
callback (@[err]);
578
583
}
579
584
}];
@@ -599,7 +604,7 @@ - (NSDictionary *) handleFirebaseError:(NSString *) name
599
604
[error localizedDescription ], @" rawDescription" ,
600
605
[[error userInfo ] description ], @" userInfo" ,
601
606
nil ];
602
-
607
+
603
608
NSString *description = @" Unknown error" ;
604
609
switch (error.code ) {
605
610
case FIRAuthErrorCodeInvalidEmail:
@@ -630,12 +635,12 @@ - (NSDictionary *) userPropsFromFIRUser:(FIRUser *) user
630
635
@" anonymous" : @(user.anonymous ),
631
636
@" displayName" : user.displayName ? user.displayName : @" "
632
637
} mutableCopy];
633
-
638
+
634
639
if ([user valueForKey: @" photoURL" ] != nil ) {
635
640
[userProps setValue: [NSString stringWithFormat: @" %@ " , user.photoURL]
636
641
forKey: @" photoURL" ];
637
642
}
638
-
643
+
639
644
return userProps;
640
645
}
641
646
0 commit comments