Answer the question
In order to leave comments, you need to log in
Obj-C How to work with streams correctly?
In general, this is the situation, I use the AFNetworking library, I execute a POST request - authorization, the request goes fine, but when the request is in progress and the user clicks the "Login" button again , strange things happen, since the previous request did not have time to work out, and then there is more one, I certainly understand that it is possible to create a BOOL variable, and when the request is in process, do not call the authorization method, but it is very long, especially when there are many methods, how else can this error be avoided? Surely there are worked out schemes, maybe I searched very badly - but I did not find a solution to the situation on Google .
Request example:
- (IBAction)login:(UIButton *)sender {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"_login": @"bar", @"_pass" : @"123"};
[manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
Answer the question
In order to leave comments, you need to log in
in this particular case you just need to disable the button
- (IBAction)login:(UIButton *)sender {
sender.enabled = NO;
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"_login": @"bar", @"_pass" : @"123"};
[manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
sender.enabled = YES;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
sender.enabled = YES;
}];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question