29
29
#import " FIROAuthProvider.h"
30
30
31
31
#if FIREBASE_PLATFORM_IOS
32
+ // PhoneAuth is not supported on non-iOS Apple platforms (eg: tvOS).
33
+ // We are using stub implementation for these platforms (just like on desktop).
32
34
#import " FIRPhoneAuthProvider.h"
33
- #endif
35
+ #endif // FIREBASE_PLATFORM_IOS
34
36
35
37
#import " FIRTwitterAuthProvider.h"
36
38
39
+ #if FIREBASE_PLATFORM_IOS
37
40
// This object is shared between the PhoneAuthProvider::Listener and the blocks in
38
41
// @ref VerifyPhoneNumber. It exists for as long as one of those two lives. We use Objective-C
39
42
// for reference counting.
@@ -50,10 +53,13 @@ @interface PhoneListenerDataObjC : NSObject {
50
53
@end
51
54
@implementation PhoneListenerDataObjC
52
55
@end
56
+ #endif // FIREBASE_PLATFORM_IOS
53
57
54
58
namespace firebase {
55
59
namespace auth {
56
60
61
+ static const char * kMockVerificationId = " mock verification id" ;
62
+
57
63
using util::StringFromNSString;
58
64
59
65
Credential::~Credential () {
@@ -211,7 +217,7 @@ @implementation PhoneListenerDataObjC
211
217
/* *
212
218
Linking GameKit.framework without using it on macOS results in App Store rejection.
213
219
Thus we don't link GameKit.framework to our SDK directly. `optionalLocalPlayer` is used for
214
- checking whether the APP that consuming our SDK has linked GameKit.framework. If not,
220
+ checking whether the APP that consuming our SDK has linked GameKit.framework. If not,
215
221
early out.
216
222
**/
217
223
GKLocalPlayer *_Nullable optionalLocalPlayer = [[NSClassFromString (@" GKLocalPlayer" ) alloc ] init ];
@@ -223,7 +229,6 @@ @implementation PhoneListenerDataObjC
223
229
return localPlayer.isAuthenticated ;
224
230
}
225
231
226
- #if FIREBASE_PLATFORM_IOS
227
232
// We skip the implementation of ForceResendingTokenData since it is not needed.
228
233
// The ForceResendingToken class for iOS is empty.
229
234
PhoneAuthProvider::ForceResendingToken::ForceResendingToken ()
@@ -238,6 +243,7 @@ @implementation PhoneListenerDataObjC
238
243
bool PhoneAuthProvider::ForceResendingToken::operator !=(
239
244
const ForceResendingToken&) const { return false ; }
240
245
246
+ #if FIREBASE_PLATFORM_IOS
241
247
// This implementation of PhoneListenerData is specific to iOS.
242
248
struct PhoneListenerData {
243
249
// Hold the reference-counted ObjC structure. This structure is shared by the blocks in
@@ -249,7 +255,12 @@ @implementation PhoneListenerDataObjC
249
255
data_->objc = [[PhoneListenerDataObjC alloc ] init ];
250
256
data_->objc ->active_listener = this ;
251
257
}
258
+ #else // non-iOS Apple platforms (eg: tvOS)
259
+ // Stub for tvOS and other non-iOS apple platforms.
260
+ PhoneAuthProvider::Listener::Listener () : data_(nullptr ) {}
261
+ #endif // FIREBASE_PLATFORM_IOS
252
262
263
+ #if FIREBASE_PLATFORM_IOS
253
264
PhoneAuthProvider::Listener::~Listener () {
254
265
// Wait while the Listener is being used (in the callbacks in VerifyPhoneNumber).
255
266
// Then reset the active_listener so that callbacks become no-ops.
@@ -260,7 +271,11 @@ @implementation PhoneListenerDataObjC
260
271
data_->objc = nil ;
261
272
delete data_;
262
273
}
274
+ #else // non-iOS Apple platforms (eg: tvOS)
275
+ PhoneAuthProvider::Listener::~Listener () {}
276
+ #endif // FIREBASE_PLATFORM_IOS
263
277
278
+ #if FIREBASE_PLATFORM_IOS
264
279
// This implementation of PhoneAuthProviderData is specific to iOS.
265
280
struct PhoneAuthProviderData {
266
281
public:
@@ -270,10 +285,17 @@ explicit PhoneAuthProviderData(FIRPhoneAuthProvider* objc_provider)
270
285
// The wrapped provider in Objective-C.
271
286
FIRPhoneAuthProvider* objc_provider;
272
287
};
288
+ #endif // FIREBASE_PLATFORM_IOS
273
289
274
290
PhoneAuthProvider::PhoneAuthProvider () : data_(nullptr ) {}
291
+
292
+ #if FIREBASE_PLATFORM_IOS
275
293
PhoneAuthProvider::~PhoneAuthProvider () { delete data_; }
294
+ #else // non-iOS Apple platforms (eg: tvOS)
295
+ PhoneAuthProvider::~PhoneAuthProvider () {}
296
+ #endif // FIREBASE_PLATFORM_IOS
276
297
298
+ #if FIREBASE_PLATFORM_IOS
277
299
void PhoneAuthProvider::VerifyPhoneNumber (
278
300
const char * phone_number, uint32_t /* auto_verify_time_out_ms*/ ,
279
301
const ForceResendingToken* /* force_resending_token*/ , Listener* listener) {
@@ -308,7 +330,24 @@ explicit PhoneAuthProviderData(FIRPhoneAuthProvider* objc_provider)
308
330
}
309
331
}
310
332
}
333
+ #else // non-iOS Apple platforms (eg: tvOS)
334
+ void PhoneAuthProvider::VerifyPhoneNumber (
335
+ const char * /* phone_number*/ , uint32_t /* auto_verify_time_out_ms*/ ,
336
+ const ForceResendingToken* force_resending_token, Listener* listener) {
337
+ FIREBASE_ASSERT_RETURN_VOID (listener != nullptr );
338
+
339
+ // Mock the tokens by sending a new one whenever it's unspecified.
340
+ ForceResendingToken token;
341
+ if (force_resending_token != nullptr ) {
342
+ token = *force_resending_token;
343
+ }
344
+
345
+ listener->OnCodeAutoRetrievalTimeOut (kMockVerificationId );
346
+ listener->OnCodeSent (kMockVerificationId , token);
347
+ }
348
+ #endif // FIREBASE_PLATFORM_IOS
311
349
350
+ #if FIREBASE_PLATFORM_IOS
312
351
Credential PhoneAuthProvider::GetCredential (const char * verification_id,
313
352
const char * verification_code) {
314
353
FIREBASE_ASSERT_RETURN (Credential (), verification_id && verification_code);
@@ -317,7 +356,17 @@ explicit PhoneAuthProviderData(FIRPhoneAuthProvider* objc_provider)
317
356
verificationCode: @(verification_code)];
318
357
return Credential (new FIRAuthCredentialPointer ((FIRAuthCredential*)credential));
319
358
}
359
+ #else // non-iOS Apple platforms (eg: tvOS)
360
+ Credential PhoneAuthProvider::GetCredential (const char * verification_id,
361
+ const char * verification_code) {
362
+ FIREBASE_ASSERT_MESSAGE_RETURN (Credential (nullptr ), false ,
363
+ " Phone Auth is not supported on non iOS Apple platforms (eg:tvOS)." );
320
364
365
+ return Credential (nullptr );
366
+ }
367
+ #endif // FIREBASE_PLATFORM_IOS
368
+
369
+ #if FIREBASE_PLATFORM_IOS
321
370
// static
322
371
PhoneAuthProvider& PhoneAuthProvider::GetInstance (Auth* auth) {
323
372
PhoneAuthProvider& provider = auth->auth_data_ ->phone_auth_provider ;
@@ -330,6 +379,11 @@ explicit PhoneAuthProviderData(FIRPhoneAuthProvider* objc_provider)
330
379
}
331
380
return provider;
332
381
}
382
+ #else // non-iOS Apple platforms (eg: tvOS)
383
+ // static
384
+ PhoneAuthProvider& PhoneAuthProvider::GetInstance (Auth* auth) {
385
+ return auth->auth_data_ ->phone_auth_provider ;
386
+ }
333
387
#endif // FIREBASE_PLATFORM_IOS
334
388
335
389
// FederatedAuthHandlers
@@ -450,7 +504,7 @@ void ReauthenticateWithProviderGetCredentialCallback(FIRAuthCredential* _Nullabl
450
504
return future;
451
505
}
452
506
453
- #else // non iOS Apple platform
507
+ #else // non- iOS Apple platforms (eg: tvOS)
454
508
Future<SignInResult> future = MakeFuture (&futures, handle);
455
509
futures.Complete (handle, kAuthErrorApiNotAvailable ,
456
510
" Link with getCredentialWithUIDelegate is not supported on non-iOS Apple platforms." );
@@ -487,7 +541,7 @@ void ReauthenticateWithProviderGetCredentialCallback(FIRAuthCredential* _Nullabl
487
541
return future;
488
542
}
489
543
490
- #else // non iOS Apple Platform
544
+ #else // non- iOS Apple platforms (eg: tvOS)
491
545
Future<SignInResult> future = MakeFuture (&futures, handle);
492
546
futures.Complete (handle, kAuthErrorApiNotAvailable ,
493
547
" Reauthenticate with getCredentialWithUIDelegate is not supported on non-iOS Apple platforms." );
0 commit comments