Skip to content

feat: Add initial tvOS support to some firebase packages #8109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/app-check/RNFBAppCheck.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if coreVersionDetected != coreVersionRequired
end
firebase_ios_target = appPackage['sdkVersions']['ios']['iosTarget']
firebase_macos_target = appPackage['sdkVersions']['ios']['macosTarget']
firebase_tvos_target = appPackage['sdkVersions']['ios']['tvosTarget']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify this and just keep tvOS target the same as iOS.


Pod::Spec.new do |s|
s.name = "RNFBAppCheck"
Expand All @@ -25,6 +26,7 @@ Pod::Spec.new do |s|
s.social_media_url = 'http://twitter.com/invertaseio'
s.ios.deployment_target = firebase_ios_target
s.macos.deployment_target = firebase_macos_target
s.tvos.deployment_target = firebase_tvos_target
s.source_files = 'ios/**/*.{h,m}'

# React Native dependencies
Expand Down
2 changes: 2 additions & 0 deletions packages/app/RNFBApp.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
firebase_sdk_version = package['sdkVersions']['ios']['firebase']
firebase_ios_target = package['sdkVersions']['ios']['iosTarget']
firebase_macos_target = package['sdkVersions']['ios']['macosTarget']
firebase_tvos_target = package['sdkVersions']['ios']['tvosTarget']

Pod::Spec.new do |s|
s.name = "RNFBApp"
Expand All @@ -19,6 +20,7 @@ Pod::Spec.new do |s|
s.social_media_url = 'http://twitter.com/invertaseio'
s.ios.deployment_target = firebase_ios_target
s.macos.deployment_target = firebase_macos_target
s.tvos.deployment_target = firebase_tvos_target
s.cocoapods_version = '>= 1.12.0'
s.source_files = "ios/**/*.{h,m}"

Expand Down
3 changes: 2 additions & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
"ios": {
"firebase": "11.4.0",
"iosTarget": "13.0",
"macosTarget": "10.15"
"macosTarget": "10.15",
"tvosTarget": "12.0"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be 13.4 or higher for compatibility with RNTV 0.73 and later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit of a catch :) If we use firebase_ios_target for tvOS then there isn't a way set tvosTarget to to 13.4 without also setting iosTarget, which I'm not sure we want to do when most users aren't targeting tvOS?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with having these separate, and we align the minimums with the firebase-ios-sdk podspecs not with react-native. The Auth podspec over there is the highest one so it determines all, and it is currently at 13.0:

https://github.com/firebase/firebase-ios-sdk/blob/ae2554220afb03a5d6fc389c28a86061a12c7caa/FirebaseAuth.podspec#L22-L25

So in final form what I will do here is keep them separate, but bump to 13.0

},
"android": {
"minSdk": 21,
Expand Down
2 changes: 2 additions & 0 deletions packages/auth/RNFBAuth.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if coreVersionDetected != coreVersionRequired
end
firebase_ios_target = appPackage['sdkVersions']['ios']['iosTarget']
firebase_macos_target = appPackage['sdkVersions']['ios']['macosTarget']
firebase_tvos_target = appPackage['sdkVersions']['ios']['tvosTarget']

Pod::Spec.new do |s|
s.name = "RNFBAuth"
Expand All @@ -25,6 +26,7 @@ Pod::Spec.new do |s|
s.social_media_url = 'http://twitter.com/invertaseio'
s.ios.deployment_target = firebase_ios_target
s.macos.deployment_target = firebase_macos_target
s.tvos.deployment_target = firebase_tvos_target
s.source_files = 'ios/**/*.{h,m}'

# React Native dependencies
Expand Down
28 changes: 27 additions & 1 deletion packages/auth/ios/RNFBAuth/RNFBAuthModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@
static __strong NSMutableDictionary *emulatorConfigs;
// Used for caching credentials between method calls.
static __strong NSMutableDictionary<NSString *, FIRAuthCredential *> *credentials;
#if !TARGET_OS_TV
static __strong NSMutableDictionary<NSString *, FIRMultiFactorResolver *> *cachedResolver;
static __strong NSMutableDictionary<NSString *, FIRMultiFactorSession *> *cachedSessions;
#endif

@implementation RNFBAuthModule
#pragma mark -
Expand All @@ -76,8 +78,10 @@ - (id)init {
idTokenHandlers = [[NSMutableDictionary alloc] init];
emulatorConfigs = [[NSMutableDictionary alloc] init];
credentials = [[NSMutableDictionary alloc] init];
#if !TARGET_OS_TV
cachedResolver = [[NSMutableDictionary alloc] init];
cachedSessions = [[NSMutableDictionary alloc] init];
#endif
});
return self;
}
Expand All @@ -103,8 +107,10 @@ - (void)invalidate {
[idTokenHandlers removeAllObjects];

[credentials removeAllObjects];
#if !TARGET_OS_TV
[cachedResolver removeAllObjects];
[cachedSessions removeAllObjects];
#endif
}

#pragma mark -
Expand Down Expand Up @@ -415,6 +421,7 @@ - (void)invalidate {
}
}

#if !TARGET_OS_TV
RCT_EXPORT_METHOD(updatePhoneNumber
: (FIRApp *)firebaseApp
: (NSString *)provider
Expand Down Expand Up @@ -455,6 +462,7 @@ - (void)invalidate {
[self promiseNoUser:resolve rejecter:reject isError:YES];
}
}
#endif

RCT_EXPORT_METHOD(updateProfile
: (FIRApp *)firebaseApp
Expand Down Expand Up @@ -617,6 +625,7 @@ - (void)invalidate {
[builder setCustomParameters:provider[@"customParameters"]];
}

#if !TARGET_OS_TV
[builder getCredentialWithUIDelegate:nil
completion:^(FIRAuthCredential *_Nullable credential,
NSError *_Nullable error) {
Expand Down Expand Up @@ -647,6 +656,7 @@ - (void)invalidate {
}];
}
}];
#endif
}

RCT_EXPORT_METHOD(confirmPasswordReset
Expand Down Expand Up @@ -817,6 +827,7 @@ - (void)invalidate {
}];
}

#if !TARGET_OS_TV
RCT_EXPORT_METHOD(signInWithPhoneNumber
: (FIRApp *)firebaseApp
: (NSString *)phoneNumber
Expand Down Expand Up @@ -1053,6 +1064,7 @@ - (void)invalidate {
}
}];
}
#endif

RCT_EXPORT_METHOD(linkWithCredential
: (FIRApp *)firebaseApp
Expand Down Expand Up @@ -1122,6 +1134,7 @@ - (void)invalidate {
[builder setCustomParameters:provider[@"parameters"]];
}

#if !TARGET_OS_TV
[builder getCredentialWithUIDelegate:nil
completion:^(FIRAuthCredential *_Nullable credential,
NSError *_Nullable error) {
Expand Down Expand Up @@ -1151,6 +1164,7 @@ - (void)invalidate {
}];
}
}];
#endif
}

RCT_EXPORT_METHOD(unlink
Expand Down Expand Up @@ -1248,7 +1262,7 @@ - (void)invalidate {
if (provider[@"parameters"]) {
[builder setCustomParameters:provider[@"parameters"]];
}

#if !TARGET_OS_TV
[builder getCredentialWithUIDelegate:nil
completion:^(FIRAuthCredential *_Nullable credential,
NSError *_Nullable error) {
Expand Down Expand Up @@ -1279,6 +1293,7 @@ - (void)invalidate {
}];
}
}];
#endif
}

RCT_EXPORT_METHOD(fetchSignInMethodsForEmail
Expand Down Expand Up @@ -1375,10 +1390,12 @@ - (FIRAuthCredential *)getCredentialForProvider:(NSString *)provider
} else if ([provider compare:@"github.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
credential = [FIRGitHubAuthProvider credentialWithToken:authToken];
} else if ([provider compare:@"phone" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
#if !TARGET_OS_TV
DLog(@"using app credGen: %@", firebaseApp.name) credential =
[[FIRPhoneAuthProvider providerWithAuth:[FIRAuth authWithApp:firebaseApp]]
credentialWithVerificationID:authToken
verificationCode:authTokenSecret];
#endif
} else if ([provider compare:@"oauth" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
credential = [FIROAuthProvider credentialWithProviderID:@"oauth"
IDToken:authToken
Expand Down Expand Up @@ -1423,6 +1440,7 @@ - (void)promiseNoUser:(RCTPromiseResolveBlock)resolve
}
}

#if !TARGET_OS_TV
- (NSDictionary *)multiFactorResolverToDict:(FIRMultiFactorResolver *)resolver {
// Temporarily store the non-serializable session for later
NSString *sessionHash = [NSString stringWithFormat:@"%@", @([resolver.session hash])];
Expand All @@ -1433,6 +1451,7 @@ - (NSDictionary *)multiFactorResolverToDict:(FIRMultiFactorResolver *)resolver {
@"auth" : resolver.auth
};
}
#endif

- (NSString *)getJSFactorId:(NSString *)factorId {
if ([factorId isEqualToString:@"1"]) {
Expand Down Expand Up @@ -1542,14 +1561,17 @@ - (NSDictionary *)getJSError:(NSError *)error {
authCredentialDict = [self authCredentialToDict:authCredential];
}


NSDictionary *resolverDict = nil;
#if !TARGET_OS_TV
if ([error userInfo][FIRAuthErrorUserInfoMultiFactorResolverKey] != nil) {
FIRMultiFactorResolver *resolver = error.userInfo[FIRAuthErrorUserInfoMultiFactorResolverKey];
resolverDict = [self multiFactorResolverToDict:resolver];

NSString *sessionKey = [NSString stringWithFormat:@"%@", @([resolver.session hash])];
cachedResolver[sessionKey] = resolver;
}
#endif

return @{
@"code" : code,
Expand Down Expand Up @@ -1696,11 +1718,14 @@ - (NSDictionary *)firebaseUserToDict:(FIRUser *)user {
@"refreshToken" : user.refreshToken,
@"tenantId" : user.tenantID ? (id)user.tenantID : [NSNull null],
keyUid : user.uid,
#if !TARGET_OS_TV
@"multiFactor" :
@{@"enrolledFactors" : [self convertMultiFactorData:user.multiFactor.enrolledFactors]}
#endif
};
}

#if !TARGET_OS_TV
- (NSArray<NSMutableDictionary *> *)convertMultiFactorData:(NSArray<FIRMultiFactorInfo *> *)hints {
NSMutableArray *enrolledFactors = [NSMutableArray array];

Expand All @@ -1720,6 +1745,7 @@ - (NSDictionary *)firebaseUserToDict:(FIRUser *)user {
}
return enrolledFactors;
}
#endif

- (NSDictionary *)authCredentialToDict:(FIRAuthCredential *)authCredential {
NSString *authCredentialHash = [NSString stringWithFormat:@"%@", @([authCredential hash])];
Expand Down
2 changes: 2 additions & 0 deletions packages/firestore/RNFBFirestore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if coreVersionDetected != coreVersionRequired
end
firebase_ios_target = appPackage['sdkVersions']['ios']['iosTarget']
firebase_macos_target = appPackage['sdkVersions']['ios']['macosTarget']
firebase_tvos_target = appPackage['sdkVersions']['ios']['tvosTarget']

Pod::Spec.new do |s|
s.name = "RNFBFirestore"
Expand All @@ -25,6 +26,7 @@ Pod::Spec.new do |s|
s.social_media_url = 'http://twitter.com/invertaseio'
s.ios.deployment_target = firebase_ios_target
s.macos.deployment_target = firebase_macos_target
s.tvos.deployment_target = firebase_tvos_target
s.source_files = 'ios/**/*.{h,m}'

# React Native dependencies
Expand Down
2 changes: 2 additions & 0 deletions packages/functions/RNFBFunctions.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if coreVersionDetected != coreVersionRequired
end
firebase_ios_target = appPackage['sdkVersions']['ios']['iosTarget']
firebase_macos_target = appPackage['sdkVersions']['ios']['macosTarget']
firebase_tvos_target = appPackage['sdkVersions']['ios']['tvosTarget']

Pod::Spec.new do |s|
s.name = "RNFBFunctions"
Expand All @@ -25,6 +26,7 @@ Pod::Spec.new do |s|
s.social_media_url = 'http://twitter.com/invertaseio'
s.ios.deployment_target = firebase_ios_target
s.macos.deployment_target = firebase_macos_target
s.tvos.deployment_target = firebase_tvos_target
s.source_files = 'ios/**/*.{h,m}'

# React Native dependencies
Expand Down
2 changes: 2 additions & 0 deletions packages/storage/RNFBStorage.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if coreVersionDetected != coreVersionRequired
end
firebase_ios_target = appPackage['sdkVersions']['ios']['iosTarget']
firebase_macos_target = appPackage['sdkVersions']['ios']['macosTarget']
firebase_tvos_target = appPackage['sdkVersions']['ios']['tvosTarget']

Pod::Spec.new do |s|
s.name = "RNFBStorage"
Expand All @@ -25,6 +26,7 @@ Pod::Spec.new do |s|
s.social_media_url = 'http://twitter.com/invertaseio'
s.ios.deployment_target = firebase_ios_target
s.macos.deployment_target = firebase_macos_target
s.tvos.deployment_target = firebase_tvos_target
s.source_files = 'ios/**/*.{h,m}'

# React Native dependencies
Expand Down