I am using my internal api to retrieve data from my server. I am using Basic Authentication to achieve this. Because of the nature of APIs i am not implementing any session or anything else on my server code, so i am sending username and passwords with all of my requests.
Because of this, i don't want to implement NSURLConnection delegates for every viewcontroller i am using. So that, I created a helper class, which extends NSObject, and I set it as a NSURLConnectionDelegate.
@interface HandlerClass : NSObject <NSURLConnectionDelegate>
I implemented every method i need, and i am calling it like:
NSURL *URL = [NSURL URLWithString:@"https://url/ifuser/"];
NSLog(@"Connection ");
NSURLRequest *request = [NSURLRequest requestWithURL:URL
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:30.0];
NSHTTPURLResponse *response;
HandlerClass *cc = [[HandlerClass alloc] init];
cc.username = self.username.text;
cc.password = self.password.text;
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:cc];
But whatever i try, i cannot reach data response data from that delegate.
I literally tried to read every piece of writing in internet, both including stackoverflow and other sites. Every solution of this requires no authentication.
But i only need the solution with authentication.
Thanks.
~~~~~~~~~~~~~~~~~~~~~~~~~
EDIT: I know i did several redundant errors. But i could be able to figure out what did wrong. I just needed to use NSRunLoop to achieve my goal. Thanks all.