I have created a app that record video and store it on server now i want to add HUD in my application ,this HUD will show until my data will store on server.
I am using MKNetworkKit fot posting data to the server.
I have tried this:
- (void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
//NSLog(@"medea type is: %@ ",mediaType);
if ([mediaType isEqualToString:@"public.movie"]){
// NSLog(@"got a movie");
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
webData = [NSData dataWithContentsOfURL:videoURL];
}
[self dismissModalViewControllerAnimated:NO];
// Handle a movie capture
if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeMovie, 0)
== kCFCompareEqualTo) {
NSString *moviePath = [[info objectForKey:
UIImagePickerControllerMediaURL] path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath,self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
}
}
self.flUploadEngine = [[fileUploadEngine alloc] initWithHostName:@"reneveledat.net" customHeaderFields:nil];
NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"testApp", @"appID",
nil];
self.flOperation = [self.flUploadEngine postDataToServer:postParams path:@"/dilipvideotest/savefile.php"];
[self.flOperation addData:webData forKey:@"uploadfile" mimeType:@"video/mov" fileName:@"upload.mov"];
[self.flOperation onCompletion:^(MKNetworkOperation *operation) {
NSLog(@"response string is : %@", [operation responseString]);
response = [operation responseString] ;
[HUD removeFromSuperview];
/*
This is where you handle a successful 200 response
*/
}
onError:^(NSError *error) {
NSLog(@"error : %@", error);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alert show];
}];
[self.flUploadEngine enqueueOperation:self.flOperation ];
// for HUD
HUD = [[MBProgressHUD alloc] initWithView:self.view];
HUD.labelText = @"Doing funky stuff...";
HUD.detailsLabelText = @"Just relax";
HUD.mode = MBProgressHUDModeAnnularDeterminate;
[self.view addSubview:HUD];
[HUD showWhileExecuting:@selector(doSomeFunkyStuff) onTarget:self withObject:nil animated:YES];
}
- (void)doSomeFunkyStuff {
float progress = 0.0;
while (progress < 1.0) {
progress += 0.01;
HUD.progress = progress;
usleep(50000);
}
}
EDIT
its done now
i have just added this code
[HUD removeFromSuperview];
At
[self.flOperation onCompletion:^(MKNetworkOperation *operation) {
NSLog(@"response string is : %@", [operation responseString]);
response = [operation responseString] ;
[HUD removeFromSuperview];
/*
This is where you handle a successful 200 response
*/
}
You are adding the MBProgressHUD in the view.
You need to remove it after the data is uploaded to server.
So you need to write the removing code inside the completion block and error block.
like:
[self.flOperation onCompletion:^(MKNetworkOperation *operation)
{
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSLog(@"response string is : %@", [operation responseString]);
response = [operation responseString] ;
}
onError:^(NSError *error)
{
[MBProgressHUD hideHUDForView:self.view animated:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
}];