2929#import " FIROAuthProvider.h"
3030
3131#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).
3234#import " FIRPhoneAuthProvider.h"
33- #endif
35+ #endif // FIREBASE_PLATFORM_IOS
3436
3537#import " FIRTwitterAuthProvider.h"
3638
39+ #if FIREBASE_PLATFORM_IOS
3740// This object is shared between the PhoneAuthProvider::Listener and the blocks in
3841// @ref VerifyPhoneNumber. It exists for as long as one of those two lives. We use Objective-C
3942// for reference counting.
@@ -50,10 +53,13 @@ @interface PhoneListenerDataObjC : NSObject {
5053@end
5154@implementation PhoneListenerDataObjC
5255@end
56+ #endif // FIREBASE_PLATFORM_IOS
5357
5458namespace firebase {
5559namespace auth {
5660
61+ static const char * kMockVerificationId = " mock verification id" ;
62+
5763using util::StringFromNSString;
5864
5965Credential::~Credential () {
@@ -211,7 +217,7 @@ @implementation PhoneListenerDataObjC
211217 /* *
212218 Linking GameKit.framework without using it on macOS results in App Store rejection.
213219 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,
215221 early out.
216222 **/
217223 GKLocalPlayer *_Nullable optionalLocalPlayer = [[NSClassFromString (@" GKLocalPlayer" ) alloc ] init ];
@@ -223,7 +229,6 @@ @implementation PhoneListenerDataObjC
223229 return localPlayer.isAuthenticated ;
224230}
225231
226- #if FIREBASE_PLATFORM_IOS
227232// We skip the implementation of ForceResendingTokenData since it is not needed.
228233// The ForceResendingToken class for iOS is empty.
229234PhoneAuthProvider::ForceResendingToken::ForceResendingToken ()
@@ -238,6 +243,7 @@ @implementation PhoneListenerDataObjC
238243bool PhoneAuthProvider::ForceResendingToken::operator !=(
239244 const ForceResendingToken&) const { return false ; }
240245
246+ #if FIREBASE_PLATFORM_IOS
241247// This implementation of PhoneListenerData is specific to iOS.
242248struct PhoneListenerData {
243249 // Hold the reference-counted ObjC structure. This structure is shared by the blocks in
@@ -249,7 +255,12 @@ @implementation PhoneListenerDataObjC
249255 data_->objc = [[PhoneListenerDataObjC alloc ] init ];
250256 data_->objc ->active_listener = this ;
251257}
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
252262
263+ #if FIREBASE_PLATFORM_IOS
253264PhoneAuthProvider::Listener::~Listener () {
254265 // Wait while the Listener is being used (in the callbacks in VerifyPhoneNumber).
255266 // Then reset the active_listener so that callbacks become no-ops.
@@ -260,7 +271,11 @@ @implementation PhoneListenerDataObjC
260271 data_->objc = nil ;
261272 delete data_;
262273}
274+ #else // non-iOS Apple platforms (eg: tvOS)
275+ PhoneAuthProvider::Listener::~Listener () {}
276+ #endif // FIREBASE_PLATFORM_IOS
263277
278+ #if FIREBASE_PLATFORM_IOS
264279// This implementation of PhoneAuthProviderData is specific to iOS.
265280struct PhoneAuthProviderData {
266281 public:
@@ -270,10 +285,17 @@ explicit PhoneAuthProviderData(FIRPhoneAuthProvider* objc_provider)
270285 // The wrapped provider in Objective-C.
271286 FIRPhoneAuthProvider* objc_provider;
272287};
288+ #endif // FIREBASE_PLATFORM_IOS
273289
274290PhoneAuthProvider::PhoneAuthProvider () : data_(nullptr ) {}
291+
292+ #if FIREBASE_PLATFORM_IOS
275293PhoneAuthProvider::~PhoneAuthProvider () { delete data_; }
294+ #else // non-iOS Apple platforms (eg: tvOS)
295+ PhoneAuthProvider::~PhoneAuthProvider () {}
296+ #endif // FIREBASE_PLATFORM_IOS
276297
298+ #if FIREBASE_PLATFORM_IOS
277299void PhoneAuthProvider::VerifyPhoneNumber (
278300 const char * phone_number, uint32_t /* auto_verify_time_out_ms*/ ,
279301 const ForceResendingToken* /* force_resending_token*/ , Listener* listener) {
@@ -308,7 +330,24 @@ explicit PhoneAuthProviderData(FIRPhoneAuthProvider* objc_provider)
308330 }
309331 }
310332}
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
311349
350+ #if FIREBASE_PLATFORM_IOS
312351Credential PhoneAuthProvider::GetCredential (const char * verification_id,
313352 const char * verification_code) {
314353 FIREBASE_ASSERT_RETURN (Credential (), verification_id && verification_code);
@@ -317,7 +356,17 @@ explicit PhoneAuthProviderData(FIRPhoneAuthProvider* objc_provider)
317356 verificationCode: @(verification_code)];
318357 return Credential (new FIRAuthCredentialPointer ((FIRAuthCredential*)credential));
319358}
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)." );
320364
365+ return Credential (nullptr );
366+ }
367+ #endif // FIREBASE_PLATFORM_IOS
368+
369+ #if FIREBASE_PLATFORM_IOS
321370// static
322371PhoneAuthProvider& PhoneAuthProvider::GetInstance (Auth* auth) {
323372 PhoneAuthProvider& provider = auth->auth_data_ ->phone_auth_provider ;
@@ -330,6 +379,11 @@ explicit PhoneAuthProviderData(FIRPhoneAuthProvider* objc_provider)
330379 }
331380 return provider;
332381}
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+ }
333387#endif // FIREBASE_PLATFORM_IOS
334388
335389// FederatedAuthHandlers
@@ -450,7 +504,7 @@ void ReauthenticateWithProviderGetCredentialCallback(FIRAuthCredential* _Nullabl
450504 return future;
451505 }
452506
453- #else // non iOS Apple platform
507+ #else // non- iOS Apple platforms (eg: tvOS)
454508 Future<SignInResult> future = MakeFuture (&futures, handle);
455509 futures.Complete (handle, kAuthErrorApiNotAvailable ,
456510 " Link with getCredentialWithUIDelegate is not supported on non-iOS Apple platforms." );
@@ -487,7 +541,7 @@ void ReauthenticateWithProviderGetCredentialCallback(FIRAuthCredential* _Nullabl
487541 return future;
488542 }
489543
490- #else // non iOS Apple Platform
544+ #else // non- iOS Apple platforms (eg: tvOS)
491545 Future<SignInResult> future = MakeFuture (&futures, handle);
492546 futures.Complete (handle, kAuthErrorApiNotAvailable ,
493547 " Reauthenticate with getCredentialWithUIDelegate is not supported on non-iOS Apple platforms." );
0 commit comments