View Single Post
sagarshivam

 
Member Since: Jun 03, 2011
Posts: 54
sagarshivam is on a distinguished road

sagarshivam is offline
Dear All,

In my spliview based app, once I tap the file name located on main view panel, one jsp (that lies on some server) is called and then jsp returns the file location on server. Then I create NSURLConnection object to stram the file from that location and save the file to application document directory. Once streaming is completed, I pass the file's local location (as id type) to detailitem in detilviewcontroller. And then file is viewed in uiwebview in detailview.
Everything is happening properly.

But what I want is that as soon as jsp is called and while it takes time to stream the file locally , activityindicator should rotate in detailview, so that user has ad idea that something is happening.And as soon as file is loaded in webview (after file is streamed and available locally), that indicator is stopped.


I am sure this has to do something with delegat method of NSURLConnection, but I am unable to implement it properly. Also, I know the exact file size as soon as I tapped the file (Is that of any use?? May be If I use progressbar).


Part of code is:

- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {

NSString *post = [NSString stringWithFormat:@"DocId=%@",docid];
NSData *postdata = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSMutableURLRequest *request= [[[NSMutableURLRequest alloc] init] autorelease];
file_expected_size=[[file_size_list objectAtIndex:indexPath.row] longLongValue];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",DV_instance,@"/jsp/DV3_CreateFileLink_iPad.jsp"]]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: postdata];

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

if(conn){

NSURLResponse *response;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
NSString *serveroutput= [[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding];
NSString *stringurl = [serveroutput stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

NSURL *url_for_filetapped_on_Server = [NSURL URLWithString:stringurl];
NSData *data_of_file = [NSData dataWithContentsOfURL:url_for_filetapped_on_Server];



// Then I determine the local file path (which is relative_local_file_full_path) and then

detailview.detailItem =relative_local_file_full_path; (where detailview is an object of class DetailViewController)

}
}

Any idea is appreciated!!
Thanks
QUOTE Thanks