Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CNuland

macrumors newbie
Original poster
Jun 17, 2010
18
0
My app uploads data to a web server and I was wanting to have a wait screen pop up until it is done uploading. Is there a way to make an alertview without a cancel button, and then delete it after? Or maybe a better way to approach this matter?

Thanks for the help as always.

-CNuland
 
If you are really wanting to block the UI whilst the upload happens (something I wouldn't recommend), I would suggest a UIActivityIndicatorView or a UIProgressView presented modally.
 
Well, the user can't do anything while the upload happens anyway, as the IU is frozen while the upload is going on. I just want a pop up screen to let them know when the upload is finished. Though I'm completely open to suggestions. I will look into what you mentioned first though.
 
The UIActivityIndicatorView did not work. It seems that while
Code:
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
is uploading the information, the UIActivityIndicatorView quits processing. I removed that line of code and then the timer and UIActivityIndicatorView work fine. Does anyone else have any suggestions?
 
How about
Code:
connectionWithRequest:delegate:
for an asynchronous request?
 
Alright, thanks for the advice. I've been researching the difference between asynchronous and synchronous, but I'm having issues implementing that into my code. Here's what I have right now.


Code:
-(IBAction) uploadImages {
	for (AnnotatedImage* image in images) {

		NSData *imageData = UIImageJPEGRepresentation(image.image, .1);
		// setting up the URL to post to
		NSString *urlString = @"*********";
		// setting up the request object now
		NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
		[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"];
		

		NSMutableData *body = [NSMutableData data];
		[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 	
		[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"fileName\"; filename=\"%@\"\r\n",image.name] dataUsingEncoding:NSUTF8StringEncoding]];  
		[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 	
		
		
		[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 	
		[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"fileDesc\"; filename=\"%@\"\r\n",image.description] dataUsingEncoding:NSUTF8StringEncoding]];  
		[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
		
		
		
		[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
		[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n",image.name] 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]];
		// setting the body of the post to the reqeust
		
		
		[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"customerID\"\r\n\r\n%@", test] dataUsingEncoding:NSUTF8StringEncoding]];  
		[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 	
		[request setHTTPBody:body];
		
		// now lets make the connection to the web
		NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
		NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
		NSLog(returnString);
		
	}
}

I tried changing the NSData *returnData to use the initWithRequest, but it doesn't work. Compiles fine, just doesn't send. Does anyone have any advice or possibly point me in the right direction? Thanks.
 
Hi, I'm new on this forum but I have almost the same code as you. But can you pleas copy paste your code because I'm struggling with the same problem. And how did you do the asynchronous upload?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.