Skip to content

Commit

Permalink
fix(ios,macos): amend platform ifdefs
Browse files Browse the repository at this point in the history
  • Loading branch information
shirakaba committed Aug 18, 2024
1 parent 6bc4d27 commit 1872f4a
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions packages/react-native-app-auth/ios/RNAppAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ - (dispatch_queue_t)methodQueue
return dispatch_get_main_queue();
}

#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
#if TARGET_OS_IPHONE
UIBackgroundTaskIdentifier rnAppAuthTaskId;
#endif

Expand Down Expand Up @@ -358,7 +358,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
additionalParameters:additionalParameters];

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

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

#if TARGET_OS_MACCATALYST
id<OIDExternalUserAgent> externalUserAgent = nil;
#elif TARGET_OS_IOS
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
id<OIDExternalUserAgent> externalUserAgent = iosCustomBrowser != nil ? [self getCustomBrowser: iosCustomBrowser] : nil;
#elif TARGET_OS_OSX
#elif TARGET_OS_IPHONE || TARGET_OS_OSX
id<OIDExternalUserAgent> externalUserAgent = nil;
#endif

OIDAuthorizationCallback callback = ^(OIDAuthorizationResponse *_Nullable authorizationResponse, NSError *_Nullable error) {
typeof(self) strongSelf = weakSelf;
strongSelf->_currentSession = nil;
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
#if TARGET_OS_IPHONE
[UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId];
rnAppAuthTaskId = UIBackgroundTaskInvalid;
#elif TARGET_OS_OSX
Expand All @@ -418,7 +416,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
externalUserAgent:externalUserAgent
callback:callback];
} else {
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
#if TARGET_OS_IPHONE
if (@available(iOS 13, *)) {
_currentSession = [OIDAuthorizationService presentAuthorizationRequest:request
presentingViewController:presentingViewController
Expand All @@ -443,7 +441,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
) {
typeof(self) strongSelf = weakSelf;
strongSelf->_currentSession = nil;
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
#if TARGET_OS_IPHONE
[UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId];
rnAppAuthTaskId = UIBackgroundTaskInvalid;
#elif TARGET_OS_OSX
Expand All @@ -466,7 +464,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
} else {


#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
#if TARGET_OS_IPHONE
if (@available(iOS 13, *)) {
_currentSession = [OIDAuthState authStateByPresentingAuthorizationRequest:request
presentingViewController:presentingViewController
Expand Down Expand Up @@ -538,7 +536,7 @@ - (void)endSessionWithConfiguration: (OIDServiceConfiguration *) configuration
postLogoutRedirectURL: [NSURL URLWithString:postLogoutRedirectURL]
additionalParameters: additionalParameters];

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

#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
#if TARGET_OS_IPHONE
rnAppAuthTaskId = [UIApplication.sharedApplication beginBackgroundTaskWithExpirationHandler:^{
[UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId];
rnAppAuthTaskId = UIBackgroundTaskInvalid;
Expand All @@ -565,9 +563,7 @@ - (void)endSessionWithConfiguration: (OIDServiceConfiguration *) configuration
}
#endif

#if TARGET_OS_MACCATALYST
id<OIDExternalUserAgent> externalUserAgent = nil;
#elif TARGET_OS_IOS
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
id<OIDExternalUserAgent> externalUserAgent = iosCustomBrowser != nil ? [self getCustomBrowser: iosCustomBrowser] : [self getExternalUserAgentWithPresentingViewController:presentingViewController
prefersEphemeralSession:prefersEphemeralSession];
#elif TARGET_OS_OSX
Expand All @@ -579,7 +575,7 @@ - (void)endSessionWithConfiguration: (OIDServiceConfiguration *) configuration
callback: ^(OIDEndSessionResponse *_Nullable response, NSError *_Nullable error) {
typeof(self) strongSelf = weakSelf;
strongSelf->_currentSession = nil;
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
#if TARGET_OS_IPHONE
[UIApplication.sharedApplication endBackgroundTask:rnAppAuthTaskId];
rnAppAuthTaskId = UIBackgroundTaskInvalid;
#elif TARGET_OS_OSX
Expand Down Expand Up @@ -752,7 +748,7 @@ - (NSString*)getErrorCode: (NSError*) error defaultCode: (NSString *) defaultCod
return defaultCode;
}

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

Expand Down Expand Up @@ -791,7 +787,7 @@ - (NSString*)getErrorMessage: (NSError*) error {
}
}

#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
#if TARGET_OS_IPHONE
- (id<OIDExternalUserAgent>)getExternalUserAgentWithPresentingViewController: (UIViewController *)presentingViewController
prefersEphemeralSession: (BOOL) prefersEphemeralSession
#elif TARGET_OS_OSX
Expand All @@ -802,7 +798,7 @@ - (NSString*)getErrorMessage: (NSError*) error {
id<OIDExternalUserAgent> externalUserAgent;
#if TARGET_OS_MACCATALYST
externalUserAgent = [[OIDExternalUserAgentCatalyst alloc] initWithPresentingViewController:presentingViewController];
#elif TARGET_OS_IOS
#elif TARGET_OS_IPHONE
if (@available(iOS 13, *)) {
externalUserAgent = [[OIDExternalUserAgentIOS alloc] initWithPresentingViewController:
presentingViewController
Expand Down

0 comments on commit 1872f4a

Please sign in to comment.