You can send your request synchronously like this:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:subscribedAppsURL]];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (error != nil)
{
NSString *stringResponse = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"Reponse:%@", response);
//Handle the response, possible just return true here:
}
else
{
NSLog(@"Error:%@", error.localizedDescription);
}
With the intent of using delegates:
//In Header
@protocol LoginCompletionDelegate
-(void) didCompleteAndIsLoggedIn:(BOOL) loggedIn;
@end
@property (nonatomic, assign) id<LoginCompletionDelegate> delegate;
//In implementation
- (BOOL) loginWithDelegate:(id<LoginCompletionDelegate>)target username:(NSString*) username password:(NSString*)password
{
delegate = target;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:subscribedAppsURL]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connectionDict setObject:connection forKey:@"login"];
[connection release];
return true;
}
// delegate
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Finished Loading");
if (connection == [connectionDict objectForKey:@"login"]) {
[connection release];
//@TODO Here I want to function login to return true.
[delegate didCompleteAndIsLoggedIn:YES];
}
}
//There is another method that looks like this. I might have the signature a bit wrong
-(void) connection:(NSURLConnection*) connection didFailWithError:(NSError*) error
{
[delegate didCompleteAndIsLoggedIn:NO];
}