Skip to content
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

feat: add tvOS support #8111

Merged
merged 6 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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/analytics/RNFBAnalytics.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 = "RNFBAnalytics"
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-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
6 changes: 3 additions & 3 deletions packages/app-check/ios/RNFBAppCheck/RNFBAppCheckProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ - (void)configure:(FIRApp *)app
}

if ([providerName isEqualToString:@"appAttest"]) {
if (@available(iOS 14.0, macCatalyst 14.0, tvOS 15.0, watchOS 9.0, *)) {
if (@available(iOS 14.0, macOS 11.0, macCatalyst 14.0, tvOS 15.0, watchOS 9.0, *)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

self.delegateProvider = [[FIRAppAttestProvider alloc] initWithApp:app];
} else {
// This is not a valid configuration.
DLog(@"AppAttest unavailable: it requires iOS14+, macCatalyst14+ or tvOS15+. Installing "
DLog(@"AppAttest unavailable: it requires iOS14+, macOS 11+, macCatalyst14+ or tvOS15+. Installing "
@"debug provider to guarantee invalid tokens in this invalid configuration.");
self.delegateProvider = [[FIRAppCheckDebugProvider alloc] initWithApp:app];
}
}

if ([providerName isEqualToString:@"appAttestWithDeviceCheckFallback"]) {
if (@available(iOS 14.0, *)) {
if (@available(iOS 14.0, macOS 11.0, macCatalyst 14.0, tvOS 15.0, watchOS 9.0, *)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this should have been guarded for all the platforms during initial implementation, oversight

self.delegateProvider = [[FIRAppAttestProvider alloc] initWithApp:app];
} else {
self.delegateProvider = [[FIRDeviceCheckProvider alloc] initWithApp:app];
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": "13.0"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

},
"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_IOS
Copy link
Collaborator Author

@mikehardy mikehardy Nov 2, 2024

Choose a reason for hiding this comment

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

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_IOS
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_IOS
[cachedResolver removeAllObjects];
[cachedSessions removeAllObjects];
#endif
}

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

#if TARGET_OS_IOS
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_IOS
[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_IOS
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_IOS
[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_IOS
[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_IOS
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_IOS
- (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_IOS
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_IOS
@"multiFactor" :
@{@"enrolledFactors" : [self convertMultiFactorData:user.multiFactor.enrolledFactors]}
#endif
};
}

#if TARGET_OS_IOS
- (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
3 changes: 3 additions & 0 deletions packages/crashlytics/RNFBCrashlytics.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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']
firebase_sdk_version = appPackage['sdkVersions']['ios']['firebase']

Pod::Spec.new do |s|
s.name = "RNFBCrashlytics"
Expand All @@ -26,6 +28,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
3 changes: 3 additions & 0 deletions packages/database/RNFBDatabase.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ 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']
firebase_sdk_version = appPackage['sdkVersions']['ios']['firebase']

Pod::Spec.new do |s|
s.name = "RNFBDatabase"
Expand All @@ -25,6 +27,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/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
3 changes: 3 additions & 0 deletions packages/in-app-messaging/RNFBInAppMessaging.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ 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']
firebase_sdk_version = appPackage['sdkVersions']['ios']['firebase']

Pod::Spec.new do |s|
s.name = "RNFBInAppMessaging"
Expand All @@ -25,6 +27,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
3 changes: 3 additions & 0 deletions packages/installations/RNFBInstallations.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ 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']
firebase_sdk_version = appPackage['sdkVersions']['ios']['firebase']

Pod::Spec.new do |s|
s.name = "RNFBInstallations"
Expand All @@ -25,6 +27,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
3 changes: 3 additions & 0 deletions packages/ml/RNFBML.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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']
firebase_sdk_version = appPackage['sdkVersions']['ios']['firebase']

Pod::Spec.new do |s|
s.name = "RNFBML"
Expand All @@ -26,6 +28,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
Loading