Reputation: 53
I am calling a view pushing method in a completion block and it does not work, normally when i call it from another non-block method it works. I think it is related with thread but i could not work it out, what should i do?
This is my push method:
-(void)goToVenues{
venuesList *venuesList = [self.storyboard instantiateViewControllerWithIdentifier:@"VenuesList"];
[self.navigationController pushViewController:venuesList animated:YES];
}
And this is completion block:
[FSOAuth requestAccessTokenForCode:accessCode
clientId:clientID
callbackURIString:callbackURI
clientSecret:clientSecret
completionBlock:^(NSString *authToken, BOOL requestCompleted, FSOAuthErrorCode errorCode) {
[[NSUserDefaults standardUserDefaults] setObject:authToken forKey:@"token"];
[self goToVenues];
}];
Upvotes: 0
Views: 52
Reputation: 7343
Move your method call to the main thread and don't forget to syncronize the user defaults after modifying it, like this:
dispatch_async(dispatch_get_main_queue(), ^{
[[NSUserDefaults standardUserDefaults] setObject:authToken forKey:@"token"];
[[NSUserDefaults standardUserDefaults] syncronize];
[self goToVenues];
});
Upvotes: 3