@@ -35,36 +35,46 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
3535 if ([@" CloudFunctions#call" isEqualToString: call.method]) {
3636 NSString *functionName = call.arguments [@" functionName" ];
3737 NSObject *parameters = call.arguments [@" parameters" ];
38- [[FIRFunctions functions ]
39- callFunction: functionName
40- withObject: parameters
41- completion: ^(FIRHTTPSCallableResult *callableResult, NSError *error) {
42- if (error) {
43- FlutterError *flutterError;
44- if (error.domain == FIRFunctionsErrorDomain) {
45- NSDictionary *details = [NSMutableDictionary dictionary ];
46- [details setValue: [self mapFunctionsErrorCodes: error.code] forKey: @" code" ];
47- if (error.localizedDescription != nil ) {
48- [details setValue: error.localizedDescription forKey: @" message" ];
49- }
50- if (error.userInfo [FIRFunctionsErrorDetailsKey] != nil ) {
51- [details setValue: error.userInfo[FIRFunctionsErrorDetailsKey] forKey: @" details" ];
52- }
38+ NSString *appName = call.arguments [@" app" ];
39+ NSString *region = call.arguments [@" region" ];
40+ FIRApp *app = [FIRApp appNamed: appName];
41+ FIRFunctions *functions;
42+ if (region != nil ) {
43+ functions = [FIRFunctions functionsForApp: app region: region];
44+ } else {
45+ functions = [FIRFunctions functionsForApp: app];
46+ }
47+ [functions callFunction: functionName
48+ withObject: parameters
49+ completion: ^(FIRHTTPSCallableResult *callableResult, NSError *error) {
50+ if (error) {
51+ FlutterError *flutterError;
52+ if (error.domain == FIRFunctionsErrorDomain) {
53+ NSDictionary *details = [NSMutableDictionary dictionary ];
54+ [details setValue: [self mapFunctionsErrorCodes: error.code] forKey: @" code" ];
55+ if (error.localizedDescription != nil ) {
56+ [details setValue: error.localizedDescription forKey: @" message" ];
57+ }
58+ if (error.userInfo [FIRFunctionsErrorDetailsKey] != nil ) {
59+ [details setValue: error.userInfo[FIRFunctionsErrorDetailsKey]
60+ forKey: @" details" ];
61+ }
5362
54- flutterError =
55- [FlutterError errorWithCode: @" functionsError"
56- message: @" Firebase function failed with exception."
57- details: details];
58- } else {
59- flutterError = [FlutterError errorWithCode: nil
60- message: error.localizedDescription
61- details: nil ];
62- }
63- result (flutterError);
64- } else {
65- result (callableResult.data );
66- }
67- }];
63+ flutterError =
64+ [FlutterError errorWithCode: @" functionsError"
65+ message: @" Firebase function failed with exception."
66+ details: details];
67+ } else {
68+ flutterError = [FlutterError
69+ errorWithCode: [NSString stringWithFormat: @" %ld " , error.code]
70+ message: error.localizedDescription
71+ details: nil ];
72+ }
73+ result (flutterError);
74+ } else {
75+ result (callableResult.data );
76+ }
77+ }];
6878 } else {
6979 result (FlutterMethodNotImplemented);
7080 }
0 commit comments