From e5aaf90c7f8f8ca8cc54cf9097a9a936405b064f Mon Sep 17 00:00:00 2001 From: Nikita Lutsenko Date: Wed, 23 Sep 2015 12:00:44 -0700 Subject: [PATCH] Fix initialization of Facebook/Twitter Utils blocking the main thread. --- Parse/Internal/PFCoreManager.m | 2 +- .../Controller/PFUserAuthenticationController.h | 14 ++++++++++++++ .../Controller/PFUserAuthenticationController.m | 16 ++++++++++++---- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Parse/Internal/PFCoreManager.m b/Parse/Internal/PFCoreManager.m index f709f9e0c..072a1629b 100644 --- a/Parse/Internal/PFCoreManager.m +++ b/Parse/Internal/PFCoreManager.m @@ -305,7 +305,7 @@ - (PFUserAuthenticationController *)userAuthenticationController { __block PFUserAuthenticationController *controller = nil; dispatch_sync(_controllerAccessQueue, ^{ if (!_userAuthenticationController) { - _userAuthenticationController = [[PFUserAuthenticationController alloc] init]; + _userAuthenticationController = [PFUserAuthenticationController controllerWithDataSource:self]; } controller = _userAuthenticationController; }); diff --git a/Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.h b/Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.h index dc06afac5..746c2472f 100644 --- a/Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.h +++ b/Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.h @@ -12,6 +12,8 @@ #import #import +#import "PFCoreDataProvider.h" + NS_ASSUME_NONNULL_BEGIN @class BFTask PF_GENERIC(__covariant BFGenericType); @@ -19,6 +21,18 @@ NS_ASSUME_NONNULL_BEGIN @interface PFUserAuthenticationController : NSObject +@property (nonatomic, weak, readonly) id dataSource; + +///-------------------------------------- +/// @name Init +///-------------------------------------- + +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)new NS_UNAVAILABLE; + +- (instancetype)initWithDataSource:(id)dataSource; ++ (instancetype)controllerWithDataSource:(id)dataSource; + ///-------------------------------------- /// @name Authentication Providers ///-------------------------------------- diff --git a/Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.m b/Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.m index d508f38bb..2f5083861 100644 --- a/Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.m +++ b/Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.m @@ -16,6 +16,7 @@ #import "PFAnonymousUtils.h" #import "PFAnonymousAuthenticationProvider.h" #import "PFUserController.h" +#import "PFCurrentUserController.h" #import "PFAssert.h" @interface PFUserAuthenticationController () { @@ -31,16 +32,21 @@ @implementation PFUserAuthenticationController #pragma mark - Init ///-------------------------------------- -- (instancetype)init { +- (instancetype)initWithDataSource:(id)dataSource { self = [super init]; if (!self) return nil; + _dataSource = dataSource; _dataAccessQueue = dispatch_queue_create("com.parse.user.authenticationManager", DISPATCH_QUEUE_SERIAL); _authenticationDelegates = [NSMutableDictionary dictionary]; return self; } ++ (instancetype)controllerWithDataSource:(id)dataSource { + return [[self alloc] initWithDataSource:dataSource]; +} + ///-------------------------------------- #pragma mark - Authentication Providers ///-------------------------------------- @@ -56,9 +62,11 @@ - (void)registerAuthenticationDelegate:(id)delegat }); // TODO: (nlutsenko) Decouple this further. - if (![authType isEqualToString:PFAnonymousUserAuthenticationType]) { - [[PFUser currentUser] synchronizeAuthDataWithAuthType:authType]; - } + [[self.dataSource.currentUserController getCurrentUserAsyncWithOptions:0] continueWithSuccessBlock:^id(BFTask *task) { + PFUser *user = task.result; + [user synchronizeAuthDataWithAuthType:authType]; + return nil; + }]; } - (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType {