i working on uploading the images through my application.i used the following code
-(IBAction)submitimage:(id)sender
{
// [activity startAnimating]; i started activity here but it starts after completion of function
NSString *name, *comments;
comments = txtcomment.text;
name = @"Anonymous";
int r=random()%10000;
NSLog(@"random number:%d",r );
NSString *imageName=[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"dashboard\"; filename=\"%d.jpg\"\r\n",r];
NSData *imageData = UIImageJPEGRepresentation(imge, 90);
//NSLog(@"imagedata=%@",imageData);
NSString *urlString =[NSString stringWithFormat:@"http://www.xyzsite.com/webservices/&comment=%@&name=%@",comments,name];
//NSLog(@"urlsubmit=%@",urlString);
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
/* body of the post */
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:imageName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@",returnString);
}
but the animation starts after function over so is there any other way to start activity indicator.before the touch event over.i face the same problem in two different application of uploading images.so if anyone knows then plese let me know thanks
There could be more than one solution to this. However you can move the activity indication start animation action to the TouchDown event and leave the other in Touch up Inside.