@@ -39,6 +39,8 @@ @interface FIRAuthURLPresenter () <SFSafariViewControllerDelegate, FIRAuthWebVie
39
39
@implementation FIRAuthURLPresenter {
40
40
/* * @var _isPresenting
41
41
@brief Whether or not some web-based content is being presented.
42
+ Accesses to this property are serialized on the global Auth work queue
43
+ and thus this variable should not be read or written outside of the work queue.
42
44
*/
43
45
BOOL _isPresenting;
44
46
@@ -63,7 +65,9 @@ @implementation FIRAuthURLPresenter {
63
65
id <FIRAuthUIDelegate> _UIDelegate;
64
66
65
67
/* * @var _completion
66
- @brief The completion handler for the current presentaion, if one is active.
68
+ @brief The completion handler for the current presentation, if one is active.
69
+ Accesses to this variable are serialized on the global Auth work queue
70
+ and thus this variable should not be read or written outside of the work queue.
67
71
@remarks This variable is also used as a flag to indicate a presentation is active.
68
72
*/
69
73
FIRAuthURLPresentationCompletion _Nullable _completion;
@@ -75,12 +79,16 @@ - (void)presentURL:(NSURL *)URL
75
79
completion : (FIRAuthURLPresentationCompletion)completion {
76
80
if (_isPresenting) {
77
81
// Unable to start a new presentation on top of another.
78
- _completion (nil , [FIRAuthErrorUtils webContextAlreadyPresentedErrorWithMessage: nil ]);
82
+ // Invoke the new completion closure and leave the old one as-is
83
+ // to be invoked when the presentation finishes.
84
+ dispatch_async (dispatch_get_main_queue (), ^() {
85
+ completion (nil , [FIRAuthErrorUtils webContextAlreadyPresentedErrorWithMessage: nil ]);
86
+ });
79
87
return ;
80
88
}
81
89
_isPresenting = YES ;
82
90
_callbackMatcher = callbackMatcher;
83
- _completion = completion;
91
+ _completion = [ completion copy ] ;
84
92
dispatch_async (dispatch_get_main_queue (), ^() {
85
93
self->_UIDelegate = UIDelegate ?: [FIRAuthDefaultUIDelegate defaultUIDelegate ];
86
94
if ([SFSafariViewController class ]) {
@@ -162,8 +170,8 @@ - (void)finishPresentationWithURL:(nullable NSURL *)URL error:(nullable NSError
162
170
_callbackMatcher = nil ;
163
171
id <FIRAuthUIDelegate> UIDelegate = _UIDelegate;
164
172
_UIDelegate = nil ;
165
- FIRAuthURLPresentationCompletion completion = _completion;
166
- _completion = nil ;
173
+ FIRAuthURLPresentationCompletion completion = [ _completion copy ] ;
174
+ _completion = NULL ;
167
175
void (^finishBlock)(void ) = ^() {
168
176
self->_isPresenting = NO ;
169
177
completion (URL, error);
0 commit comments