Objectie-C - How do I get an API response when sending a message?

1

I'm sending a JSON to an API. When the API receives a JSON, it responds by telling me whether the procedure was successful or not. How do I get this answer?

Shipping code:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.meuSite.com.br/api/listener.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"text/json" forHTTPHeaderField:@"Content-type"];
[request setValue:[NSString stringWithFormat:@"%d", [_json length]] forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[_json dataUsingEncoding:NSUTF8StringEncoding]];

[[NSURLConnection alloc] initWithRequest: request delegate:self];
    
asked by anonymous 17.05.2016 / 21:43

1 answer

1

Through the following delegates:

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
    NSLog(@"did fail");
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    NSLog(@"did receive data");
}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
    NSLog(@"did receive response ");
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
    NSLog(@"did finish loading");
} 
    
28.05.2016 / 20:42