@@ -49,6 +49,8 @@ @interface FIRFunctions () <FIRLibrary, FIRFunctionsInstanceProvider> {
49
49
NSString *_projectID;
50
50
// The region to use for all function references.
51
51
NSString *_region;
52
+ // The custom domain to use for all functions references (optional).
53
+ NSString *_customDomain;
52
54
// A serializer to encode/decode data and return values.
53
55
FUNSerializer *_serializer;
54
56
// A factory for getting the metadata to include with function calls.
@@ -60,6 +62,7 @@ @interface FIRFunctions () <FIRLibrary, FIRFunctionsInstanceProvider> {
60
62
// Re-declare this initializer here in order to attribute it as the designated initializer.
61
63
- (instancetype )initWithProjectID : (NSString *)projectID
62
64
region : (NSString *)region
65
+ customDomain : (nullable NSString *)customDomain
63
66
auth : (nullable id <FIRAuthInterop>)auth
64
67
messaging : (nullable id <FIRMessagingInterop>)messaging
65
68
NS_DESIGNATED_INITIALIZER;
@@ -89,30 +92,44 @@ + (void)load {
89
92
}
90
93
91
94
+ (instancetype )functions {
92
- return [[self alloc ] initWithApp: [FIRApp defaultApp ] region: kFUNDefaultRegion ];
95
+ return [[self alloc ] initWithApp: [FIRApp defaultApp ] region: kFUNDefaultRegion customDomain: nil ];
93
96
}
94
97
95
98
+ (instancetype )functionsForApp : (FIRApp *)app {
96
- return [[self alloc ] initWithApp: app region: kFUNDefaultRegion ];
99
+ return [[self alloc ] initWithApp: app region: kFUNDefaultRegion customDomain: nil ];
97
100
}
98
101
99
102
+ (instancetype )functionsForRegion : (NSString *)region {
100
- return [[self alloc ] initWithApp: [FIRApp defaultApp ] region: region];
103
+ return [[self alloc ] initWithApp: [FIRApp defaultApp ] region: region customDomain: nil ];
104
+ }
105
+
106
+ + (instancetype )functionsForCustomDomain : (NSString *)customDomain {
107
+ return [[self alloc ] initWithApp: [FIRApp defaultApp ]
108
+ region: kFUNDefaultRegion
109
+ customDomain: customDomain];
101
110
}
102
111
103
112
+ (instancetype )functionsForApp : (FIRApp *)app region : (NSString *)region {
104
- return [[self alloc ] initWithApp: app region: region];
113
+ return [[self alloc ] initWithApp: app region: region customDomain: nil ];
105
114
}
106
115
107
- - (instancetype )initWithApp : (FIRApp *)app region : (NSString *)region {
116
+ + (instancetype )functionsForApp : (FIRApp *)app customDomain : (NSString *)customDomain {
117
+ return [[self alloc ] initWithApp: app region: kFUNDefaultRegion customDomain: customDomain];
118
+ }
119
+
120
+ - (instancetype )initWithApp : (FIRApp *)app
121
+ region : (NSString *)region
122
+ customDomain : (nullable NSString *)customDomain {
108
123
return [self initWithProjectID: app.options.projectID
109
124
region: region
125
+ customDomain: customDomain
110
126
auth: FIR_COMPONENT (FIRAuthInterop, app.container)
111
127
messaging: FIR_COMPONENT (FIRMessagingInterop, app.container)];
112
128
}
113
129
114
130
- (instancetype )initWithProjectID : (NSString *)projectID
115
131
region : (NSString *)region
132
+ customDomain : (nullable NSString *)customDomain
116
133
auth : (nullable id <FIRAuthInterop>)auth
117
134
messaging : (nullable id <FIRMessagingInterop>)messaging {
118
135
self = [super init ];
@@ -123,6 +140,7 @@ - (instancetype)initWithProjectID:(NSString *)projectID
123
140
_fetcherService = [[GTMSessionFetcherService alloc ] init ];
124
141
_projectID = [projectID copy ];
125
142
_region = [region copy ];
143
+ _customDomain = [customDomain copy ];
126
144
_serializer = [[FUNSerializer alloc ] init ];
127
145
_contextProvider = [[FUNContextProvider alloc ] initWithAuth: auth messaging: messaging];
128
146
_emulatorOrigin = nil ;
@@ -148,6 +166,9 @@ - (NSString *)URLWithName:(NSString *)name {
148
166
if (_emulatorOrigin) {
149
167
return [NSString stringWithFormat: @" %@ /%@ /%@ /%@ " , _emulatorOrigin, _projectID, _region, name];
150
168
}
169
+ if (_customDomain) {
170
+ return [NSString stringWithFormat: @" %@ /%@ " , _customDomain, name];
171
+ }
151
172
return
152
173
[NSString stringWithFormat: @" https://%@ -%@ .cloudfunctions.net/%@ " , _region, _projectID, name];
153
174
}
0 commit comments