this 1 of activity hit url using nsurl connection , parse data , json data data in byte code as
nsstring *ptr= { 82, 111, 111, 116, 32, 50, 32, 48, 32, 82, 10, 47, 83, 105, 122, 101, 32, 51, 50, 10, 47, 73, 110, 102, 111, 32, 49, 32, 48, 32, 82, 10, 62, 62, 10, 115, 116, 97, 114, 116, 120, 114, 101, 102, 10, 49, 52, 51, 52, 50, 55, 10, 37, 37, 69, 79, 70, 10.........etc }
i got in nsstring , after
nsmutablearray *bytes=[[nsmutablearray alloc]init]; [bytes addobject:ptr]; nsmutabledata *data = [[nsmutabledata alloc] initwithcapacity:bytes.count]; nslog(@"file %@",data); (nsnumber *byteval in bytes) { byte b = (byte)(byteval.intvalue); [data appendbytes:&b length:1]; } nsarray *docdirectories = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *docdirectory = [docdirectories objectatindex:0]; nsstring *filename = [docdirectory stringbyappendingpathcomponent:@"abcd.pdf"]; nslog(@"file %@",filename); [data writetofile:filename atomically:no]; nsstring *resourcedocpath = [[nsstring alloc] initwithstring:[[[[nsbundle mainbundle] resourcepath] stringbydeletinglastpathcomponent] stringbyappendingpathcomponent:@"documents"]]; nsstring *filepath = [resourcedocpath stringbyappendingpathcomponent:@"abcd.pdf"]; nsurl *targeturl = [nsurl fileurlwithpath:filepath]; nsurlrequest *requestfile = [nsurlrequest requestwithurl:targeturl]; nslog(@"request path %@",requestfile);
this output. creates pdf can't understand how open , see generated pdf file.
file /users/rahulsharma/library/application support/iphone simulator/6.1/applications/cd29ed82-8039-411f-8bba-2784e5445ede/documents/abcd.pdf
request path <nsurlrequestfile://localhost/users/rahulsharma/library/application%20support/iphone%20simulator/6.1/applications/cd29ed82-8039-411f-8bba-2784e5445ede/documents/abcd.pdf>
please me solve problem on how pdf.
nsstring *responsetext; nsmutablearray *bytearray; viewdidload { [self report]; } -(void)report { finished=false; nsstring *case_id=[nsstring stringwithformat:@"8cc61590-42b0-4433-b8ee-25e40d5e6033"]; nsstring *investigation_id=[nsstring stringwithformat:@"33a8b03f-4ad2-424a-8aa9-02a07d3937eb"]; nsstring *test_id=[nsstring stringwithformat:@"e5a7e867-422c-4365-b920-87fdf5d82783"]; dictionary = [nsmutabledictionary dictionary]; [dictionary setobject:case_id forkey:@"caseid"]; [dictionary setobject:investigation_id forkey:@"investigationid"]; [dictionary setobject:test_id forkey:@"testid"]; // [dictionary setobject:procedure forkey:@"proc"]; // [dictionnary setobject:count forkey:@"count"]; nslog(@"dict %@",dictionary); nserror *error = nil; nsdata *jsondata = [nsjsonserialization datawithjsonobject:dictionary options:kniloptions error:&error]; nslog(@"json %@",jsondata); nsurl *url1 = [nsurl urlwithstring:@"http://192.168.1.202:81/laboratorymodule/lisservice.asmx/getpatienttestreport"]; nslog(@"url %@",url1); nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url1]; [request sethttpmethod:@"post"]; [request addvalue: @"application/json; charset=utf-8" forhttpheaderfield:@"content-type"]; [request sethttpbody:jsondata]; nsurlconnection *theconnection = [[nsurlconnection alloc] initwithrequest:request delegate:self]; if( theconnection ) { webdata = [nsmutabledata data] ; nslog(@"%@",webdata); } else { nslog(@"theconnection null"); } while(!finished) { [[nsrunloop currentrunloop] runmode:nsdefaultrunloopmode beforedate:[nsdate distantfuture]]; }
}
-(void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response { [webdata setlength: 0]; nslog(@"web = %@",webdata); } -(void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data { [webdata appenddata:data]; nslog(@"web = %@",webdata); } -(void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error { nslog(@"error theconenction"); } -(void)connectiondidfinishloading:(nsurlconnection *)connection { responsetext = [[nsstring alloc] initwithdata:self.webdata encoding:nsutf8stringencoding]; nslog(@"val %@",responsetext); sbjsonparser *par=[[sbjsonparser alloc]init]; nsstring *filecontent=[[nsstring alloc]initwithstring:responsetext]; nsdictionary *data=(nsdictionary*)[par objectwithstring:filecontent error:nil]; nslog(@" data %@",data); bytearray=[data objectforkey:@"d"]; nslog(@" string %@",bytearray); nslog(@"done. received bytes: %d", [webdata length]); finished=true; }
if want open , view pdf file in iphone can use uiwebview
open , show pdf file. pass requestfile
in -
[webview loadrequest:requestfile];
here webview
variable name uiwebview
.
Comments
Post a Comment