ios - Program skips NSURLRequest used to download txt file, if placed in IB action with other code -
i using nsurl request in objective -c in order download webpage , place in text file. similar curl function used in unix.
here code:
nsstring *documentdir = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) firstobject]; nsstring *filepath = [documentdir stringbyappendingpathcomponent:@"data.txt"]; nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:@"https://ca.finance.yahoo.com/q?s=jnj"]]; [nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue currentqueue] completionhandler:^(nsurlresponse *response, nsdata *data, nserror *error) { if (error) { nslog(@"download error:%@",error.description); } if (data) { [data writetofile:filepath atomically:yes]; nslog(@"file saved %@",filepath); } }];
i finding if execute code in own ib action (no other code) linked test button working no bugs.
however in main ib action program compiler seems skipping on code , not executing (observed lack of downloaded file). appreciate feedback on possible sources of bug.
you must create nsoperationqueue
instance:
[nsurlconnection sendasynchronousrequest:request [nsoperationqueue new] completionhandler:^(nsurlresponse *response, nsdata *data, nserror *error) {
Comments
Post a Comment