Skip to content

Commit 1872f4a

Browse files
committed
fix(ios,macos): amend platform ifdefs
Based on these: facebook/react-native#42278
1 parent 6bc4d27 commit 1872f4a

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

packages/react-native-app-auth/ios/RNAppAuth.m

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ - (dispatch_queue_t)methodQueue
2424
return dispatch_get_main_queue();
2525
}
2626

27-
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
27+
#if TARGET_OS_IPHONE
2828
UIBackgroundTaskIdentifier rnAppAuthTaskId;
2929
#endif
3030

@@ -358,7 +358,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
358358
additionalParameters:additionalParameters];
359359

360360
// performs authentication request
361-
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
361+
#if TARGET_OS_IPHONE
362362
id<UIApplicationDelegate, RNAppAuthAuthorizationFlowManager> appDelegate = (id<UIApplicationDelegate, RNAppAuthAuthorizationFlowManager>)[UIApplication sharedApplication].delegate;
363363
#elif TARGET_OS_OSX
364364
id<NSApplicationDelegate, RNAppAuthAuthorizationFlowManager> appDelegate = (id<NSApplicationDelegate, RNAppAuthAuthorizationFlowManager>)[NSApplication sharedApplication].delegate;
@@ -370,7 +370,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
370370
appDelegate.authorizationFlowManagerDelegate = self;
371371
__weak typeof(self) weakSelf = self;
372372

373-
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
373+
#if TARGET_OS_IPHONE
374374
rnAppAuthTaskId = [UIApplication.sharedApplication beginBackgroundTaskWithExpirationHandler:^{
375375
[UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId];
376376
rnAppAuthTaskId = UIBackgroundTaskInvalid;
@@ -385,18 +385,16 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
385385
}
386386
#endif
387387

388-
#if TARGET_OS_MACCATALYST
389-
id<OIDExternalUserAgent> externalUserAgent = nil;
390-
#elif TARGET_OS_IOS
388+
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
391389
id<OIDExternalUserAgent> externalUserAgent = iosCustomBrowser != nil ? [self getCustomBrowser: iosCustomBrowser] : nil;
392-
#elif TARGET_OS_OSX
390+
#elif TARGET_OS_IPHONE || TARGET_OS_OSX
393391
id<OIDExternalUserAgent> externalUserAgent = nil;
394392
#endif
395393

396394
OIDAuthorizationCallback callback = ^(OIDAuthorizationResponse *_Nullable authorizationResponse, NSError *_Nullable error) {
397395
typeof(self) strongSelf = weakSelf;
398396
strongSelf->_currentSession = nil;
399-
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
397+
#if TARGET_OS_IPHONE
400398
[UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId];
401399
rnAppAuthTaskId = UIBackgroundTaskInvalid;
402400
#elif TARGET_OS_OSX
@@ -418,7 +416,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
418416
externalUserAgent:externalUserAgent
419417
callback:callback];
420418
} else {
421-
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
419+
#if TARGET_OS_IPHONE
422420
if (@available(iOS 13, *)) {
423421
_currentSession = [OIDAuthorizationService presentAuthorizationRequest:request
424422
presentingViewController:presentingViewController
@@ -443,7 +441,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
443441
) {
444442
typeof(self) strongSelf = weakSelf;
445443
strongSelf->_currentSession = nil;
446-
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
444+
#if TARGET_OS_IPHONE
447445
[UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId];
448446
rnAppAuthTaskId = UIBackgroundTaskInvalid;
449447
#elif TARGET_OS_OSX
@@ -466,7 +464,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
466464
} else {
467465

468466

469-
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
467+
#if TARGET_OS_IPHONE
470468
if (@available(iOS 13, *)) {
471469
_currentSession = [OIDAuthState authStateByPresentingAuthorizationRequest:request
472470
presentingViewController:presentingViewController
@@ -538,7 +536,7 @@ - (void)endSessionWithConfiguration: (OIDServiceConfiguration *) configuration
538536
postLogoutRedirectURL: [NSURL URLWithString:postLogoutRedirectURL]
539537
additionalParameters: additionalParameters];
540538

541-
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
539+
#if TARGET_OS_IPHONE
542540
id<UIApplicationDelegate, RNAppAuthAuthorizationFlowManager> appDelegate = (id<UIApplicationDelegate, RNAppAuthAuthorizationFlowManager>)[UIApplication sharedApplication].delegate;
543541
#elif TARGET_OS_OSX
544542
id<NSApplicationDelegate, RNAppAuthAuthorizationFlowManager> appDelegate = (id<NSApplicationDelegate, RNAppAuthAuthorizationFlowManager>)[NSApplication sharedApplication].delegate;
@@ -550,7 +548,7 @@ - (void)endSessionWithConfiguration: (OIDServiceConfiguration *) configuration
550548
appDelegate.authorizationFlowManagerDelegate = self;
551549
__weak typeof(self) weakSelf = self;
552550

553-
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
551+
#if TARGET_OS_IPHONE
554552
rnAppAuthTaskId = [UIApplication.sharedApplication beginBackgroundTaskWithExpirationHandler:^{
555553
[UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId];
556554
rnAppAuthTaskId = UIBackgroundTaskInvalid;
@@ -565,9 +563,7 @@ - (void)endSessionWithConfiguration: (OIDServiceConfiguration *) configuration
565563
}
566564
#endif
567565

568-
#if TARGET_OS_MACCATALYST
569-
id<OIDExternalUserAgent> externalUserAgent = nil;
570-
#elif TARGET_OS_IOS
566+
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
571567
id<OIDExternalUserAgent> externalUserAgent = iosCustomBrowser != nil ? [self getCustomBrowser: iosCustomBrowser] : [self getExternalUserAgentWithPresentingViewController:presentingViewController
572568
prefersEphemeralSession:prefersEphemeralSession];
573569
#elif TARGET_OS_OSX
@@ -579,7 +575,7 @@ - (void)endSessionWithConfiguration: (OIDServiceConfiguration *) configuration
579575
callback: ^(OIDEndSessionResponse *_Nullable response, NSError *_Nullable error) {
580576
typeof(self) strongSelf = weakSelf;
581577
strongSelf->_currentSession = nil;
582-
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
578+
#if TARGET_OS_IPHONE
583579
[UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId];
584580
rnAppAuthTaskId = UIBackgroundTaskInvalid;
585581
#elif TARGET_OS_OSX
@@ -752,7 +748,7 @@ - (NSString*)getErrorCode: (NSError*) error defaultCode: (NSString *) defaultCod
752748
return defaultCode;
753749
}
754750

755-
#if TARGET_OS_IOS
751+
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
756752
- (id<OIDExternalUserAgent>)getCustomBrowser: (NSString *) browserType {
757753
typedef id<OIDExternalUserAgent> (^BrowserBlock)(void);
758754

@@ -791,7 +787,7 @@ - (NSString*)getErrorMessage: (NSError*) error {
791787
}
792788
}
793789

794-
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
790+
#if TARGET_OS_IPHONE
795791
- (id<OIDExternalUserAgent>)getExternalUserAgentWithPresentingViewController: (UIViewController *)presentingViewController
796792
prefersEphemeralSession: (BOOL) prefersEphemeralSession
797793
#elif TARGET_OS_OSX
@@ -802,7 +798,7 @@ - (NSString*)getErrorMessage: (NSError*) error {
802798
id<OIDExternalUserAgent> externalUserAgent;
803799
#if TARGET_OS_MACCATALYST
804800
externalUserAgent = [[OIDExternalUserAgentCatalyst alloc] initWithPresentingViewController:presentingViewController];
805-
#elif TARGET_OS_IOS
801+
#elif TARGET_OS_IPHONE
806802
if (@available(iOS 13, *)) {
807803
externalUserAgent = [[OIDExternalUserAgentIOS alloc] initWithPresentingViewController:
808804
presentingViewController

0 commit comments

Comments
 (0)