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 8117169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:04:32+00:00 2026-06-06T04:04:32+00:00

[NSURLConnection sendAsynchronousRequest:req queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{

  • 0
[NSURLConnection sendAsynchronousRequest:req queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
    dispatch_async(dispatch_get_main_queue(), ^{
        if(data != nil && self.superview != nil) { // <-- EXC_BAD_ACCESS on this line
            [self.musicItemImg setAlpha:0.0];
            [self.musicItemImg setImage:[UIImage imageWithData:data]];
            [UIView animateWithDuration:0.25 animations:^{
                [self.musicItemImg setAlpha:1.0];
            }];
        }
    });
}];

Sometimes this view is removed before the async load is finished and when it tries to use self I get an EXC_BAD_ACCESS and understandably so. Can I abort an async connection? Or is there a better way to combat this?

  • 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-06-06T04:04:33+00:00Added an answer on June 6, 2026 at 4:04 am

    First of all it is very bad style to start url requests in a UIView subclass. You should do that in a view controller!

    The NSOperationQueue should be a class instance of the view controller. Also the views you need to configure in the completion handler must be class instances (properties). Use the same operation queue for all requests. In viewWillDisappear you can cancel all request operations with:

    [self.operationQueue cancelAllOperations];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error]; NSString *data = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
NSString *url = @http://localhost/xml; NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; [NSURLConnection sendAsynchronousRequest:req queue:[[NSOperationQueue alloc]
i wrote the following code : NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString
I have been using NSURLConnection's sendAsynchronousRequest:queue:completionHandler: method which is great. But, I now need
NSURLResponse *response =[[NSURLResponse alloc] initWithURL:requestingURL MIMEType:@text/xml expectedContentLength:-1 textEncodingName:nil]; webData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:response error:NULL];
I'm using NSURLConnection with sendAsynchronousRequest method (and handing the data in block). Using above
I use sendSynchronousRequest:returningResponse:error method of NSURLConnection class to get NSData from network. http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html NSData
Im using the standard: [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error]; method, but while the request is
I have the following code. NSData *pageData = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL]; NSString *webpage
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:loadUrl]]; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSMutableString

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.