diff options
author | Xiangtian Dai <xiangtian@google.com> | 2017-09-01 14:38:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-01 14:38:45 -0700 |
commit | 1e9d6526109908ebd129ff30957a5b4d11d42e62 (patch) | |
tree | 8b5c38b661bebec643b01bec17d6f314a12e5472 /Firebase/Auth/Source/FIRAuthAPNSTokenManager.m | |
parent | 36c20d92b7a1f4ac5cb950df61d381ee60be9670 (diff) |
Swizzles APNs token error app delegate method for faster turnaround. (#226)
Also removes the server request in case the token is missing.
Diffstat (limited to 'Firebase/Auth/Source/FIRAuthAPNSTokenManager.m')
-rw-r--r-- | Firebase/Auth/Source/FIRAuthAPNSTokenManager.m | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Firebase/Auth/Source/FIRAuthAPNSTokenManager.m b/Firebase/Auth/Source/FIRAuthAPNSTokenManager.m index 300b7e3..a4e4389 100644 --- a/Firebase/Auth/Source/FIRAuthAPNSTokenManager.m +++ b/Firebase/Auth/Source/FIRAuthAPNSTokenManager.m @@ -58,7 +58,7 @@ static const NSTimeInterval kLegacyRegistrationTimeout = 30; - (void)getTokenWithCallback:(FIRAuthAPNSTokenCallback)callback { if (_token) { - callback(_token); + callback(_token, nil); return; } if (_pendingCallbacks) { @@ -77,9 +77,13 @@ static const NSTimeInterval kLegacyRegistrationTimeout = 30; #pragma clang diagnostic pop } }); + NSArray<FIRAuthAPNSTokenCallback> *applicableCallbacks = _pendingCallbacks; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_timeout * NSEC_PER_SEC)), FIRAuthGlobalWorkQueue(), ^{ - [self callBack]; + // Only cancel if the pending callbacks remain the same, i.e., not triggered yet. + if (applicableCallbacks == _pendingCallbacks) { + [self callBackWithToken:nil error:nil]; + } }); } @@ -97,22 +101,28 @@ static const NSTimeInterval kLegacyRegistrationTimeout = 30; token = [[FIRAuthAPNSToken alloc] initWithData:token.data type:detectedTokenType]; } _token = token; - [self callBack]; + [self callBackWithToken:token error:nil]; +} + +- (void)cancelWithError:(NSError *)error { + [self callBackWithToken:nil error:error]; } #pragma mark - Internal methods /** @fn callBack - @brief Calls back all pending callbacks with the current APNs token, if one is available. + @brief Calls back all pending callbacks with APNs token or error. + @param token The APNs token if one is available. + @param error The error occurred, if any. */ -- (void)callBack { +- (void)callBackWithToken:(nullable FIRAuthAPNSToken *)token error:(nullable NSError *)error { if (!_pendingCallbacks) { return; } NSArray<FIRAuthAPNSTokenCallback> *allCallbacks = _pendingCallbacks; _pendingCallbacks = nil; for (FIRAuthAPNSTokenCallback callback in allCallbacks) { - callback(_token); + callback(token, error); } }; |