Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6193199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:04:41+00:00 2026-05-24T03:04:41+00:00

UIImagePickerController freezes while I think the Image is being compressed or being sent by

  • 0

UIImagePickerController freezes while I think the Image is being compressed or being sent by NSURLConnection although I’m not convinced it’s the later.

What I want is, all this to be done in the background. Instead when I pick a photo from the library, the Screen freezes for what feels like forever. This isn’t optimal, obviously. What approach should I take here?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo
{
int i = 0;
NSString *uniquePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/selectedImage.png"];

while ([[NSFileManager defaultManager] fileExistsAtPath:uniquePath])
{
    uniquePath = [NSString stringWithFormat:@"%@/%@-%d.%@", [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"], @"selectedImage", ++i, @"png"];
}

NSLog(@"Writing selected Image to Documents Folder, %@", uniquePath);

dataForPNGFile = UIImagePNGRepresentation(img);

if (!dataForPNGFile) return NO;

[UIImagePNGRepresentation(img) writeToFile:uniquePath atomically:YES];
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
[[self parentViewController] dismissModalViewControllerAnimated:YES];
[picker release];

NSString *urlString = @"http://localhost:3000/photos";
NSURL *url = [NSURL URLWithString:urlString];
NSString *boundary = @"----1010101010";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

NSString *photoPath = [[NSBundle mainBundle] pathForResource:@" my-photo " ofType:@"jpg"];
NSData *photoData = [NSData dataWithContentsOfFile:photoPath];

NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"photo-description\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"testing 123" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
//  [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"photo-file\"; filename=\"%@\"\r\n", " my-photo.jpg"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:photoData];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"tags\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"random,test,example" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
[request addValue:[NSString stringWithFormat:@"%d", body.length] forHTTPHeaderField: @"Content-Length"];

[[NSURLConnection alloc] initWithRequest:request delegate:self];

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:04:41+00:00Added an answer on May 24, 2026 at 3:04 am

    You should use:

    detachNewThreadSelector:toTarget:withObject:

    Detaches a new thread and uses the specified selector as the thread entry point.

    + (void)detachNewThreadSelector:(SEL)aSelector toTarget:(id)aTarget withObject:(id)anArgument
    

    Documentation here: NSThread

    This will create a new thread for the operation that is eating up the cpu, so your UI isn’t affected remember to create a NSAutoreleasePool for the new thread, as only the main thread gets a NSAutoreleasePool pool by default.

    So at the beginning of your selector do:

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
    //and at the end:
    
    [pool drain]:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to get the image that is being displayed on the UIImagePickerController when
I have a UIImagePickerController, and while it's loading, I want to display a disclaimer
UIImagePickerController is easy to use, but i'm all of a sudden finding it exasperating
I have taken an image from UIImagePickerController , but the file looks too big
I'm using the UIImagePickerController to choose an image, and display it to the user
I am using UIImagePickerController for get photos from the device and I want to
I am using the UIImagePickerController in order to let the user select an image
I am using a UIImagePickerController in my application. After selecting an image by user,
I have a UIImagePickerController which I use to record video. now i want to
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *tempImage = [info objectForKey:UIImagePickerControllerOriginalImage]; imgview.image = tempImage; [self

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.