vendredi 27 février 2015

Huge delay on DELETE requests with 204 response and no content in objectve-c

I'm having problem with iOS app (I'm not iOS developer, I'm responsible for API that that app uses) and DELETE requests.


Api is using 204 responses with no content for DELETE requests and that have worked fine for all the client applications so far, without any problems.


The issue is that when using NSUrlConnection all those DELETE requests either are processed for more than 60 seconds or fail because of timeout.


This behaviour is only visible in out iOS implementations, other clients are getting response for exactly same request in less than 100ms.


Is this common behaviour? Do anyone know any fix for that that hopefully doesn't require API rebuild?


Code below was created just to emulate this behaviour and replicate problem on API development team side, but problem is the same (Access token obscured of course, authentication works fine):



//
// ViewController.m
// NoteablesTest

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *loadingLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[_loadingLabel setHidden:true];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)didButtonTouched:(id)sender {
NSString *url = @"http://ift.tt/1DOGSJr";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];

[request setHTTPMethod:@"DELETE"];

[request setValue:@"Bearer XXXX" forHTTPHeaderField:@"Authorization"];

[request setValue:@"Noteables/1.0 (iPhone; iOS 8.1.3; Scale/2.00)" forHTTPHeaderField:@"User-Agent"];

[request setValue:@"application/vnd.api.v1+json" forHTTPHeaderField:@"Content-Type"];

[request setValue:@"en;q=1" forHTTPHeaderField:@"Accept-Language"];

NSDate *start = [NSDate date];

[_loadingLabel setHidden:false];

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

double timePassed = [start timeIntervalSinceNow];
NSString *message = [NSString stringWithFormat:@"Elapsed: %f seconds", timePassed];
[_loadingLabel setHidden:true];


UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result!" message: message delegate:self cancelButtonTitle:@"Am I satisfied with this?" otherButtonTitles:nil, nil];

[alert show];

NSLog(@"%@", response);
}];


}

@end



Aucun commentaire:

Enregistrer un commentaire