I am sending a request, than i get some redirect link. I don't want to open that link because its not exist, its only give me some token id .
Problem is , that i don't get the redirect delegate to be called . I have added the delegate with :
than the request and the redirect delegates :
NSURLConnectionDelegate,NSURLConnectionDataDelegate>
Than request :
-(void)getAccessToken
{
NSString *baseUrl=@"my url that is working on a browser";
NSURL *url = [NSURL URLWithString:[baseUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
//data is nil
}];
}
//delegate
- (NSURLRequest *)connection: (NSURLConnection *)connection
willSendRequest: (NSURLRequest *)request
redirectResponse: (NSURLResponse *)redirectResponse;
{
NSLog(@"***** %@",request); //NOT LOGGED
if (redirectResponse)
{
}
else
{
}
return request;
}
If you start the connection with sendAsynchronousRequest:queue:completionHandler:
then you are not setting a delegate and no delegate callback methods will be called.
If you want to use the delegate methods you need to start the connection with initWithRequest:delegate:startImmediately:
.