objective c - connection : didReceiveData is not called -
i having problem in nsurlconnection. didrecievedata method not being called . dont know what's problem. went through previous problems nothing seems solve.
please me out. code.
-(void)getthejsondata { nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:_serveraddress cachepolicy:nsurlrequestuseprotocolcachepolicy timeoutinterval:10]; [request sethttpmethod: @"get"]; nsurlconnection *connection = [[nsurlconnection alloc] initwithrequest:request delegate:self startimmediately:yes]; nslog(@"this displayed"); } -(void)connection:(nsurlconnection*)connection didreceivedata:(nsdata *)data { nslog(@"this not displayed."); appappdelegate *jsondata = (appappdelegate*)[[uiapplication sharedapplication] delegate]; jsondata.userloginjsondata = [[nsdata alloc] initwithdata:data]; nserror *error; _result = [nsjsonserialization jsonobjectwithdata:jsondata.userloginjsondata options:nsjsonreadingmutablecontainers error: &error]; nsstring *test = [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding]; nslog(@"json data : %@",test); } -(void) connectiondidfinishloading:(nsurlconnection*) connection { appappdelegate *resultofjsondata = (appappdelegate*)[[uiapplication sharedapplication] delegate]; resultofjsondata.jsondataresult = _result; }
you didn't start request. need:
[connection start];
or
nsurlconnection *connection = [[nsurlconnection alloc] initwithrequest:request delegate:self startimmediately:yes];
edit: comment below had incorrect method name. try implementing both:
- (void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response
and
- (void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error
and see if either of being hit.
Comments
Post a Comment