diff options
author | 2017-06-02 18:42:17 +0100 | |
---|---|---|
committer | 2017-06-02 10:42:17 -0700 | |
commit | 5c59342e6e19989c012877362af529b3d5d0abeb (patch) | |
tree | 457f5da7c41ee45b8d3f55f83017fff2ab718781 /Firebase/Auth/Source/FIRAuth.m | |
parent | 6f700dd6c81711a8605c2587b4f2acfd4e07466b (diff) |
macOS (#38)
* Example/Core: create macOS app/tests target
* Example/Core: Core_Example/Tests -> Core_Example/Tests_iOS
* Example/Core: macOS building/tests passing
* Example/Database: separate iOS/macOS targets
* BuildFrameworks: macOS
* .travis.yml, test.sh: AllUnitTests -> AllUnitTests_iOS
* test.sh: add AllUnitTests_macOS
* Example/Storage: Example/Tests->_iOS
* Example/Storage: macOS
* test.sh: try to prevent double error 65
* test.sh: build before test
* Example/Auth|Messaging: -> _iOS
* Example/Auth: macOS build
* Example/Auth: macOS passing
* Example/Firebase: pod de/re-integrate; fix static DerivedData references; copy phase for OCMock
* Example/Firebase: manually copied OCMock, Products Dir vs. Frameworks
* Example/Firebase: copied OCMock, prevent header removal
* Example/Storage: integration tests sdk fix
* Example/Auth: macOS exclude FIRAuthAppCredentialManager; cleanup
* Firebase/Core: remove nullability annotation
* Firebase/Core|Database: correct TARGET_X usage for correctness and anticipation of OS_WATCH|TV branches
* build.swift: style fix
* Firebase/Core: FIRLogger: fix macOS intermittent va_list error
Diffstat (limited to 'Firebase/Auth/Source/FIRAuth.m')
-rw-r--r-- | Firebase/Auth/Source/FIRAuth.m | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/Firebase/Auth/Source/FIRAuth.m b/Firebase/Auth/Source/FIRAuth.m index 5b1da8c..dca0c1d 100644 --- a/Firebase/Auth/Source/FIRAuth.m +++ b/Firebase/Auth/Source/FIRAuth.m @@ -23,10 +23,6 @@ #import "AuthProviders/EmailPassword/FIREmailPasswordAuthCredential.h" #import "AuthProviders/Phone/FIRPhoneAuthCredential_Internal.h" #import "Private/FIRAdditionalUserInfo_Internal.h" -#import "Private/FIRAuthAPNSToken.h" -#import "Private/FIRAuthAPNSTokenManager.h" -#import "Private/FIRAuthAppCredentialManager.h" -#import "Private/FIRAuthAppDelegateProxy.h" #import "Private/FIRAuthCredential_Internal.h" #import "Private/FIRAuthDataResult_Internal.h" #import "Private/FIRAuthDispatcher.h" @@ -34,7 +30,6 @@ #import "FIRAuthExceptionUtils.h" #import "Private/FIRAuthGlobalWorkQueue.h" #import "Private/FIRAuthKeychain.h" -#import "Private/FIRAuthNotificationManager.h" #import "Private/FIRUser_Internal.h" #import "FirebaseAuth.h" #import "FIRAuthBackend.h" @@ -59,6 +54,14 @@ #import "FIRVerifyPhoneNumberRequest.h" #import "FIRVerifyPhoneNumberResponse.h" +#if TARGET_OS_IOS +#import "Private/FIRAuthAPNSToken.h" +#import "Private/FIRAuthAPNSTokenManager.h" +#import "Private/FIRAuthAppCredentialManager.h" +#import "Private/FIRAuthAppDelegateProxy.h" +#import "Private/FIRAuthNotificationManager.h" +#endif + #pragma mark - Constants NSString *const FIRAuthStateDidChangeInternalNotification = @@ -173,7 +176,11 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; #pragma mark - FIRAuth +#if TARGET_OS_IOS @interface FIRAuth () <FIRAuthAppDelegateHandler> +#else +@interface FIRAuth () +#endif /** @property firebaseAppId @brief The Firebase app ID. @@ -309,6 +316,8 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; FIRLogInfo(kFIRLoggerAuth, @"I-AUT000002", @"Token auto-refresh enabled."); strongSelf->_autoRefreshTokens = YES; [strongSelf scheduleAutoTokenRefresh]; + + #if TARGET_OS_IOS // TODO: Is a similar mechanism needed on macOS? strongSelf->_applicationDidBecomeActiveObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil @@ -332,6 +341,7 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; strongSelf->_isAppInBackground = YES; } }]; + #endif } if (!strongSelf.currentUser) { dispatch_async(dispatch_get_main_queue(), ^{ @@ -378,14 +388,20 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; FIRLogError(kFIRLoggerAuth, @"I-AUT000001", @"Error loading saved user when starting up: %@", error); } + + #if TARGET_OS_IOS // Initialize for phone number auth. _tokenManager = [[FIRAuthAPNSTokenManager alloc] initWithApplication:[UIApplication sharedApplication]]; + _appCredentialManager = [[FIRAuthAppCredentialManager alloc] initWithKeychain:_keychain]; + _notificationManager = [[FIRAuthNotificationManager alloc] initWithApplication:[UIApplication sharedApplication] appCredentialManager:_appCredentialManager]; + [[FIRAuthAppDelegateProxy sharedInstance] addHandler:self]; + #endif } return self; } @@ -398,12 +414,15 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; [defaultCenter removeObserver:handleToRemove]; [_listenerHandles removeLastObject]; } + + #if TARGET_OS_IOS [defaultCenter removeObserver:_applicationDidBecomeActiveObserver name:UIApplicationDidBecomeActiveNotification object:nil]; [defaultCenter removeObserver:_applicationDidEnterBackgroundObserver name:UIApplicationDidEnterBackgroundNotification object:nil]; + #endif } } @@ -520,6 +539,7 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; return; } + #if TARGET_OS_IOS if ([credential isKindOfClass:[FIRPhoneAuthCredential class]]) { // Special case for phone auth credential FIRPhoneAuthCredential *phoneCredential = (FIRPhoneAuthCredential *)credential; @@ -533,6 +553,7 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; }]; return; } + #endif FIRVerifyAssertionRequest *request = [[FIRVerifyAssertionRequest alloc] initWithAPIKey:_APIKey providerID:credential.provider]; @@ -839,7 +860,8 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; } } -- (NSData *)APNStoken { +#if TARGET_OS_IOS +- (NSData *)APNSToken { __block NSData *result = nil; dispatch_sync(FIRAuthGlobalWorkQueue(), ^{ result = _tokenManager.token.data; @@ -864,9 +886,11 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; }); return result; } +#endif #pragma mark - Internal Methods +#if TARGET_OS_IOS /** @fn signInWithPhoneCredential:callback: @brief Signs in using a phone credential. @param credential The Phone Auth credential used to sign in. @@ -922,6 +946,7 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; callback:callback]; }]; } +#endif - (void)notifyListenersOfAuthStateChangeWithUser:(FIRUser *)user token:(NSString *)token { if (user && _autoRefreshTokens) { |