My Singleton Class isn't executing a block method, objective-c

54 views Asked by At

The method I'm calling

-(void)initialLoginUser{

        __block BOOL jobDone = NO;
        __weak typeof(self) weakSelf = self;

        [self setSelf:^{   // block method gets called but it never enters this block


        NSLog(@"Entered here"); //never arrives here
        [weakSelf uploadUserData]; //here
        jobDone = YES;  //or here

    }];

    NSDate *loopUntil = [NSDate dateWithTimeIntervalSinceNow:10];
    while (jobDone == NO && [loopUntil timeIntervalSinceNow] > 0) {
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
                                 beforeDate:loopUntil];
    }

}

The block I'm calling

- (void)setSelf:(void(^)(void))callBack{
    if ([FBSDKAccessToken currentAccessToken]) {
        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"/me" parameters:nil]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, NSDictionary* result, NSError *error) {
             if (!error) {
                 dispatch_async(dispatch_get_main_queue(), ^{
                     myUser.userID = credentialsProvider.identityId;
                     myUser.firstName = [result objectForKey:@"first_name"];
                     myUser.lastName = [result objectForKey:@"last_Name"];
                     myUser.facebookID = [result objectForKey:@"id"];
                 });

             }
         }];
    }
}

Unfortunately I'm relatively new to the topic of threading and blocks so I might seem a little uneducated in this field. However I have used blocks before and I know that it probably should be executing the code within my block. setSelf is also working perfectly when until it has to execute the block. I can tell this because the myUser object is set up perfectly.

This may be completely irrelevant but I want to avoid any lack of explanation so I wanted to mention that all these methods are called from my singleton class. Please let me know if you have any idea why the inside of the block of setSelf never gets called.

Thank you

0

There are 0 answers