Created
January 29, 2014 20:25
-
-
Save seivan/8696247 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Hmm lets not clear up the blocks because lol. ~ Seivan. | |
__block XXCurrentUser * user = nil; | |
dispatch_group_t groupRequestMyProfile = dispatch_group_create(); | |
dispatch_group_t groupSaveMyProfile = dispatch_group_create(); | |
dispatch_group_t groupRequestMyApplications = dispatch_group_create(); | |
dispatch_group_t groupRequestMyNotifications = dispatch_group_create(); | |
[[XXClient sharedManager] setObserverDidSignInBlock:^(XXAccessCredential *accessCredential, NSError *error) { | |
[[LUKeychainAccess standardKeychainAccess] setObject:accessCredential forKey:NSStringFromClass([self class])]; | |
if(error)theBlock(nil,error); | |
else dispatch_group_leave(groupRequestMyProfile); | |
}]; | |
dispatch_group_enter(groupRequestMyProfile); | |
dispatch_group_notify(groupRequestMyProfile, dispatch_get_main_queue(), ^{ | |
[[XXClient sharedManager] requestMyProfile:^(NSDictionary *responseObject, NSError * error) { | |
if(error) theBlock(nil, error); | |
else { | |
user = [self objectFromResponseDictionary:responseObject]; | |
dispatch_group_leave(groupSaveMyProfile); | |
} | |
}]; | |
}); | |
dispatch_group_enter(groupSaveMyProfile); | |
dispatch_group_notify(groupSaveMyProfile, dispatch_get_main_queue(), ^{ | |
[[MagicalRecordStack defaultStack].context MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) { | |
if(error) theBlock(nil,error); | |
else dispatch_group_leave(groupRequestMyApplications); | |
}]; | |
}); | |
dispatch_group_enter(groupRequestMyApplications); | |
dispatch_group_notify(groupRequestMyApplications, dispatch_get_main_queue(), ^{ | |
[user requestGrantedApplicationsOnCompletionBlock:^(XXCurrentUser *currentUser, NSError *error) { | |
if(error) theBlock(nil,error); | |
else dispatch_group_leave(groupRequestMyNotifications); | |
}]; | |
}); | |
dispatch_group_enter(groupRequestMyNotifications); | |
dispatch_group_notify(groupRequestMyNotifications, dispatch_get_main_queue(), ^{ | |
[user requestActionsOnCompletionBlock:^(XXCurrentUser *currentUser, NSError *error) { | |
if(error) theBlock(nil,error); | |
else theBlock(currentUser, error); | |
}]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment