Skip to content

Commit

Permalink
feat: Add initial tvOS support to some firebase packages
Browse files Browse the repository at this point in the history
Adds compatibility with tvOS (using react-native-tvos) for RNFirebase packages: app, auth, firestore, functions, storage and app check
  • Loading branch information
adamkoch committed Nov 1, 2024
1 parent 88d3362 commit 5514099
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 2 deletions.
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']

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"
},
"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

0 comments on commit 5514099

Please sign in to comment.