[functions][ios] regions, multiapp & useFunctionsEmulator support
This commit is contained in:
parent
a061006759
commit
5fa86b8d1f
|
@ -1,4 +1,5 @@
|
|||
#import "RNFirebaseFunctions.h"
|
||||
#import "RNFirebaseUtil.h"
|
||||
|
||||
#if __has_include(<FirebaseFunctions/FIRFunctions.h>)
|
||||
#import <FirebaseFunctions/FIRFunctions.h>
|
||||
|
@ -9,6 +10,10 @@
|
|||
RCT_EXPORT_MODULE();
|
||||
|
||||
RCT_EXPORT_METHOD(httpsCallable:
|
||||
(NSString *) appName
|
||||
region:
|
||||
(NSString *) region
|
||||
name:
|
||||
(NSString *) name
|
||||
wrapper:
|
||||
(NSDictionary *) wrapper
|
||||
|
@ -16,20 +21,26 @@ RCT_EXPORT_METHOD(httpsCallable:
|
|||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject
|
||||
) {
|
||||
FIRFunctions *functions = [FIRFunctions functions];
|
||||
){
|
||||
FIRApp *firebaseApp = [RNFirebaseUtil getApp:appName];
|
||||
FIRFunctions *functions = [FIRFunctions functionsForApp:firebaseApp region:region];
|
||||
|
||||
[[functions HTTPSCallableWithName:name] callWithObject:[wrapper valueForKey:@"data"] completion:^(FIRHTTPSCallableResult * _Nullable result, NSError * _Nullable error) {
|
||||
FIRHTTPSCallable *callable = [functions HTTPSCallableWithName:name];
|
||||
|
||||
[callable
|
||||
callWithObject:[wrapper valueForKey:@"data"]
|
||||
completion:^(FIRHTTPSCallableResult * _Nullable result, NSError * _Nullable error) {
|
||||
if (error) {
|
||||
NSObject *details = [NSNull null];
|
||||
NSString *message = error.localizedDescription;
|
||||
|
||||
if (error.domain == FIRFunctionsErrorDomain) {
|
||||
details = error.userInfo[FIRFunctionsErrorDetailsKey];
|
||||
if (details == nil) {
|
||||
details = [NSNull null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resolve(@{
|
||||
@"__error": @true,
|
||||
@"code": [self getErrorCodeName:error],
|
||||
|
@ -40,7 +51,23 @@ RCT_EXPORT_METHOD(httpsCallable:
|
|||
resolve(@{ @"data": [result data] });
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(useFunctionsEmulator:
|
||||
(NSString *) appName
|
||||
region:
|
||||
(NSString *) region
|
||||
origin:
|
||||
(NSString *) origin
|
||||
resolver:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject
|
||||
){
|
||||
FIRApp *firebaseApp = [RNFirebaseUtil getApp:appName];
|
||||
FIRFunctions *functions = [FIRFunctions functionsForApp:firebaseApp region:region];
|
||||
[functions useFunctionsEmulatorOrigin:origin];
|
||||
resolve([NSNull null]);
|
||||
}
|
||||
|
||||
- (NSString *)getErrorCodeName:(NSError *)error {
|
||||
|
|
Loading…
Reference in New Issue