Skip to content

Commit e5aaf90

Browse files
committed
Fix initialization of Facebook/Twitter Utils blocking the main thread.
1 parent d311b20 commit e5aaf90

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

Parse/Internal/PFCoreManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ - (PFUserAuthenticationController *)userAuthenticationController {
305305
__block PFUserAuthenticationController *controller = nil;
306306
dispatch_sync(_controllerAccessQueue, ^{
307307
if (!_userAuthenticationController) {
308-
_userAuthenticationController = [[PFUserAuthenticationController alloc] init];
308+
_userAuthenticationController = [PFUserAuthenticationController controllerWithDataSource:self];
309309
}
310310
controller = _userAuthenticationController;
311311
});

Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,27 @@
1212
#import <Parse/PFConstants.h>
1313
#import <Parse/PFUserAuthenticationDelegate.h>
1414

15+
#import "PFCoreDataProvider.h"
16+
1517
NS_ASSUME_NONNULL_BEGIN
1618

1719
@class BFTask PF_GENERIC(__covariant BFGenericType);
1820
@class PFUser;
1921

2022
@interface PFUserAuthenticationController : NSObject
2123

24+
@property (nonatomic, weak, readonly) id<PFCurrentUserControllerProvider> dataSource;
25+
26+
///--------------------------------------
27+
/// @name Init
28+
///--------------------------------------
29+
30+
- (instancetype)init NS_UNAVAILABLE;
31+
+ (instancetype)new NS_UNAVAILABLE;
32+
33+
- (instancetype)initWithDataSource:(id<PFCurrentUserControllerProvider>)dataSource;
34+
+ (instancetype)controllerWithDataSource:(id<PFCurrentUserControllerProvider>)dataSource;
35+
2236
///--------------------------------------
2337
/// @name Authentication Providers
2438
///--------------------------------------

Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.m

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#import "PFAnonymousUtils.h"
1717
#import "PFAnonymousAuthenticationProvider.h"
1818
#import "PFUserController.h"
19+
#import "PFCurrentUserController.h"
1920
#import "PFAssert.h"
2021

2122
@interface PFUserAuthenticationController () {
@@ -31,16 +32,21 @@ @implementation PFUserAuthenticationController
3132
#pragma mark - Init
3233
///--------------------------------------
3334

34-
- (instancetype)init {
35+
- (instancetype)initWithDataSource:(id<PFCurrentUserControllerProvider>)dataSource {
3536
self = [super init];
3637
if (!self) return nil;
3738

39+
_dataSource = dataSource;
3840
_dataAccessQueue = dispatch_queue_create("com.parse.user.authenticationManager", DISPATCH_QUEUE_SERIAL);
3941
_authenticationDelegates = [NSMutableDictionary dictionary];
4042

4143
return self;
4244
}
4345

46+
+ (instancetype)controllerWithDataSource:(id<PFCurrentUserControllerProvider>)dataSource {
47+
return [[self alloc] initWithDataSource:dataSource];
48+
}
49+
4450
///--------------------------------------
4551
#pragma mark - Authentication Providers
4652
///--------------------------------------
@@ -56,9 +62,11 @@ - (void)registerAuthenticationDelegate:(id<PFUserAuthenticationDelegate>)delegat
5662
});
5763

5864
// TODO: (nlutsenko) Decouple this further.
59-
if (![authType isEqualToString:PFAnonymousUserAuthenticationType]) {
60-
[[PFUser currentUser] synchronizeAuthDataWithAuthType:authType];
61-
}
65+
[[self.dataSource.currentUserController getCurrentUserAsyncWithOptions:0] continueWithSuccessBlock:^id(BFTask *task) {
66+
PFUser *user = task.result;
67+
[user synchronizeAuthDataWithAuthType:authType];
68+
return nil;
69+
}];
6270
}
6371

6472
- (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType {

0 commit comments

Comments
 (0)