Skip to content

Commit 1e0d420

Browse files
author
Kadi Kraman
authored
Merge pull request #415 from georgeloring/master
Add call to beginBackgroundTaskWithExpirationHandler before presenting authorization request
2 parents 76c3411 + 008cbc1 commit 1e0d420

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ios/RNAppAuth.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ - (dispatch_queue_t)methodQueue
2424
return dispatch_get_main_queue();
2525
}
2626

27+
UIBackgroundTaskIdentifier taskId;
28+
2729
/*! @brief Number of random bytes generated for the @ state.
2830
*/
2931
static NSUInteger const kStateSizeBytes = 32;
@@ -205,12 +207,20 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
205207
}
206208
appDelegate.authorizationFlowManagerDelegate = self;
207209
__weak typeof(self) weakSelf = self;
210+
211+
taskId = [UIApplication.sharedApplication beginBackgroundTaskWithExpirationHandler:^{
212+
[UIApplication.sharedApplication endBackgroundTask:taskId];
213+
taskId = UIBackgroundTaskInvalid;
214+
}];
215+
208216
_currentSession = [OIDAuthState authStateByPresentingAuthorizationRequest:request
209217
presentingViewController:appDelegate.window.rootViewController
210218
callback:^(OIDAuthState *_Nullable authState,
211219
NSError *_Nullable error) {
212220
typeof(self) strongSelf = weakSelf;
213221
strongSelf->_currentSession = nil;
222+
[UIApplication.sharedApplication endBackgroundTask:taskId];
223+
taskId = UIBackgroundTaskInvalid;
214224
if (authState) {
215225
resolve([self formatResponse:authState.lastTokenResponse
216226
withAuthResponse:authState.lastAuthorizationResponse]);

0 commit comments

Comments
 (0)