Wait Screen or Alert?

Discussion in 'iOS Programming' started by CNuland, Jun 23, 2010.

  1. CNuland macrumors newbie

    Joined:
    Jun 17, 2010
    #1
    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
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    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.
     
  3. CNuland thread starter macrumors newbie

    Joined:
    Jun 17, 2010
    #3
    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.
     
  4. CNuland thread starter macrumors newbie

    Joined:
    Jun 17, 2010
    #4
    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?
     
  5. seepel macrumors 6502

    seepel

    Joined:
    Dec 22, 2009
    #5
    How about
    Code:
    connectionWithRequest:delegate:
    for an asynchronous request?
     
  6. CNuland thread starter macrumors newbie

    Joined:
    Jun 17, 2010
    #6
    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.
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    You need to use initWithRequest:delegate: if you want it asynchronous. Then you'll also need to have your delegate methods set up to handle the response.
     
  8. CNuland thread starter macrumors newbie

    Joined:
    Jun 17, 2010
    #8
    Alright, I got it working, thanks so much for your help!
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    You're welcome.
     
  10. Macjonh macrumors newbie

    Joined:
    Dec 27, 2010
    #10
    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?
     

Share This Page