i have a UIImagePickerController this code below runs fine on XCODE 3.2 but app hangs wen complied from XCODE 4.2
Also but sometimes it runs on some other machines once .
Can anyone tell me d reason from this? Thanks alot.
-(IBAction)showActionSheet:(id)sender {
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Add Photo" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Take Photo" otherButtonTitles:@"Choose From Library", nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[popupQuery showInView:self.view];
[popupQuery release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
[self addLoaderWithtext:@"Please wait..."];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
// [self.mtextView resignFirstResponder];
// [self.mtextView2 resignFirstResponder];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
[picker release];
} else if (buttonIndex == 1) {
[self addLoaderWithtext:@"Please wait..."];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
- (IBAction)pushUpload {
[self removeLoader];
[self addLoaderWithtext:@"Uploading Image..."];
double compressionRatio=0;
UIImage *inputImage = [UIImage imageWithCGImage:[imageView.image CGImage] scale:1.0 orientation:UIImageOrientationRight];
//imageView.image = [[UIImage imageView.image]_imageScaledToSize:CGSizeMake(32.0f, 32.0f) interpolationQuality:1];
NSData *imageData=UIImageJPEGRepresentation(inputImage,compressionRatio);
NSString *urlString = @"XXXXXXXXXXXXXXXXXXXXXXXXX";
//while ([imageData length]>1) {
// compressionRatio=compressionRatio*0.5;
// imageData=UIImageJPEGRepresentation(imageView.image,compressionRatio);
// }
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"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n"] 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];
imageurl = returnString;
NSLog(@"returnString:%@",returnString);
[NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(onTick1:) userInfo:nil repeats:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)info {
[NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(onTick1:) userInfo:nil repeats:YES];
double compressionRatio=1;
imageView.image=UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],compressionRatio);
while ([imageView.image length]>1) {
compressionRatio=compressionRatio*0.1;
imageView.image=UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],compressionRatio);
}
imageView.image = image;
[self pushUpload];
[picker.parentViewController dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [picker.parentViewController dismissModalViewControllerAnimated:YES]; }