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

  • Home
  • SEARCH
  • 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 3488034
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:13:18+00:00 2026-05-18T11:13:18+00:00

I would like to start a server request, you can cancel. My idea is

  • 0

I would like to start a server request, you can cancel.

My idea is to start the request in a thread so that the user interface does not freeze. So you can kill the whole thread including the request with a click on a “Cancel”-button.

With Android it works: the server request gets started in a “AsyncTask” and in the “onReturn()”-method I can react as soon as the server request finish.

How can I implement this using Objective-C on iOS?
My first attempt was a “NSInvocationOperation”. You can cancel the operation, but it’s difficult to handle when a request is completed and results are available. I think NSInvocationOperation is not the solution for my issue.

The would you recommend to me? Is NSThread the right choice for me?

Thank you very much!

  • 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-18T11:13:18+00:00Added an answer on May 18, 2026 at 11:13 am

    Note!

    This extremely old answer is now here only for historic purposes.

    The wonderful ASIHttpRequest library no longer exists; technology is totally different now.


    It is unbelievably simple to do this with ASIHttpRequest.

    (Asynchronous is so simple, there is no reason you would ever do it not-asynchronously.)

    Here are some rough extracts that might get you started.

    ...
    ASIFormDataRequest *request;
    ...
    NSURL *url = [NSURL URLWithString:@"https://blah.blah/blah.cgi?blah"];
    request = [ASIFormDataRequest requestWithURL:url];
    
    [request setPostValue:@"fred" forKey:@"username"];
    [request setPostValue:@"flint" forKey:@"passie"];
    [request setPostValue:@"stone" forKey:@"town"];
    
    // send up data...
    [request setData:[NSData dataWithBytes:blah length:blah] forKey:@"thefile"];
    
    // or perhaps something like...
    [request setData:imageData withFileName:@"blah.png"
            andContentType:@"image/jpeg" forKey:@"photoimage"];
    
    [request setDelegate:self];
    [request setDidFinishSelector:@selector(postingDone:)];
    [request setDidFailSelector:@selector(postingDoneProblem:)];
    [request startAsynchronous];
    ...
    
    -(void) postingDone:(ASIHTTPRequest *)request
        {
        // it worked
        }
    -(void) postingDoneProblem:(ASIHTTPRequest *)request
        {
        // failed
        }
    

    Couldn’t really be any easier. You’re basically just typing out the fields and values.

    Per your question, here is how you cancel an “in-flight” request… just set the delegate to nil and then “cancel” it.

      [myRequest setDelegate:nil];
      [myRequest cancel];
      [myRequest release];
    

    ASIHttpRequest is the “miracle library”. If you are new to iOS, ASIHttpRequest is simply THE most used 3rd party library. Essentially, every single iPhone app of the 300,000 iPhone apps uses it.

    If at all possible BE SURE to donate a few bucks to the guy — if he stops supporting that library, 100,000 iPhone programmers are buggered!

    the documentation is trivial, a child can follow it:
    http://allseeing-i.com/ASIHTTPRequest/How-to-use
    “Creating an asynchronous request”

    it is probably – almost certainly – the most amazingly simple networking library on any platform. It is trivial to do what you describe, happily. Enjoy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an iPhone app and would like to create some sort of
I am going to start a new online trading simulation game. Server Page: A
Consider a PHP web application whose purpose is to accept user requests to start
I have a windows service that is heavily multithreaded. Each thread calls various methods
I have a GWT application which I would like to run from within a
All, I am trying to cancel two concurrent HttpWebRequests using a method similar to
I've been away from web design/development for a long, long now and have recently
I am working with a Rails 3RC app and using Phusion Passenger for the
I decided to invest a few hours in trying to secure my site with
I have a background service running which sends out emails to users of my

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.