Connection
Posted
by pepersview
on Stack Overflow
See other posts from Stack Overflow
or by pepersview
Published on 2009-07-09T19:05:00Z
Indexed on
2010/04/19
22:03 UTC
Read the original article
Hit count: 331
iphone-sdk
|objective-c
Hello,
I would like to ask you about NSURLConnection
in objective-c for iPhone.
I have one app that needs to connect to one webservice to receive data (about YouTube videos), Then I have all the things that I need to connect (Similar to Hello_Soap sample code in the web).
But now, my problem is that I create a class (inherits from NSObject
) named Connection
and I have implemented the methods:
didReceiveResponse
, didReceiveData
, didFailWithError
and connectionDidFinishLoading
. Also the method:
-(void)Connect:(NSString *) soapMessage{
NSLog(soapMessage);
NSURL *url = [NSURL URLWithString:@"http://....."];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
}
But when from my AppDelegate I create one Connection
object:
Connection * connect = [[Connection alloc] Init:num]; //It's only one param to test.
[connect Connect:method.soapMessage];
And I call this method, when this finishes, it doesn't continue calling didReceiveResponse
, didReceiveData
, didFailWithError
or connectionDidFinishLoading
.
I'm trying to do this but I can't for the moment.
The thing I would like to do is to be able to call this class "Connection" each time that I want to receive data (after that to be parsed and displayed in UITableView
s).
Thank you.
© Stack Overflow or respective owner