ios - Using NSURLConnection to retrive data -


i've got api (http://www.timeapi.org/utc/now) gives time string , want use nsurlconnection retrieve it, except i'm confused how nsurlconnection works.

current code:

+(nsstring *) fetchtime {     nsstring *timestring=@"not_set";      //code url request here     nsurl *timeurl = [nsurl urlwithstring:@"http://www.timeapi.org/utc/now"]      return timestring; } 

the method called view controller in turn display on screen per mvc, need example me in right direction.

in order make request api need this:

nsurl *timeurl = [nsurl urlwithstring:@"http://www.timeapi.org/utc/now"] nsurlrequest *urlrequest = [nsurlrequest requestwithurl:url                                             cachepolicy:nsurlrequestreloadignoringcachedata                                         timeoutinterval:120]; nsdata *urldata; nsurlresponse *response; nserror *error;  urldata = [nsurlconnection sendsynchronousrequest:urlrequest                                 returningresponse:&response                                             error:&error];  nsstring *string = [[nsstring alloc] initwithdata:urldata encoding:nsutf8stringencoding]; 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -