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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:23:15+00:00 2026-05-24T09:23:15+00:00

I am making a async request and I’m getting a EXC_BAD_ACCESS on [responseData setLength:0];

  • 0

I am making a async request and I’m getting a EXC_BAD_ACCESS on [responseData setLength:0];

The Code is:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [responseData setLength:0];
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"Connection failed: %@", [error description]);
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    [responseData release];

    luckyNumbers1 = [responseString JSONValue];

    NSUserDefaults *information = [NSUserDefaults standardUserDefaults];
    /*NSArray *luckyNumbers = [json objectWithString:responseString error:&error];*/
    NSLog(@"luckyNumbers1: %@", luckyNumbers1);
    NSLog(@"user Info array is: %@", luckyNumbers1);
    // [information setObject:[NSString stringWithFormat:@"%@", (NSString *)[luckyNumbers1 objectForKey:@"session"]] forKey:@"sessionID"];
    NSDictionary *array = (NSDictionary *)[luckyNumbers1 objectForKey:@"data"];
    NSEnumerator *inner = [luckyNumbers1 objectEnumerator];
    id value;
    while((value = [inner nextObject])) {
        NSLog(@"user Info array is: %@", value);
        if ( [value isKindOfClass:[NSDictionary class]] ) {
            [information setObject:[value objectForKey:@"id"] forKey:@"userID"];
            NSLog(@"uid is: %@", [value objectForKey:@"id"]);
            [information setObject:[NSString stringWithFormat:@"%@", (NSString *)[value objectForKey:@"points_all"]] forKey:@"pointString"];
            [information setObject:[NSString stringWithFormat:@"%@", (NSString *)[[[value objectForKey:@"leaderboards"] objectForKey:@"all"] objectForKey:@"position"]] forKey:@"rankString"];
            if ((NSNull *)[value objectForKey:@"display_name"] == [NSNull null]) {
                [information setObject:@"No Display Name" forKey:@"displayNameString"];
            } else {
                [information setObject:[NSString stringWithFormat:@"%@", (NSString *)[value objectForKey:@"display_name"]] forKey:@"displayNameString"];
            }
            if ((NSNull *)[value objectForKey:@"level"] == [NSNull null]) {} else {
                [information setObject:[NSString stringWithFormat:@"%@", (NSString *)[[[value objectForKey:@"level"] objectForKey:@"definition"] objectForKey:@"name"]] forKey:@"levelString"];
            }
            pointsTV = [[UILabel alloc] initWithFrame:CGRectMake(222, 294, 441, 22)];
            pointsTV.text = [NSString stringWithFormat:@"Points: %@", [information stringForKey:@"pointString"]];
            pointsTV.backgroundColor = [UIColor clearColor];
            pointsTV.textColor = [UIColor whiteColor];
            [TVWindow addSubview:pointsTV];

            rankLabelTV = [[UILabel alloc] initWithFrame:CGRectMake(222, 269, 441, 22)];
            rankLabelTV.backgroundColor = [UIColor clearColor];
            rankLabelTV.textColor = [UIColor whiteColor];
            rankLabelTV.text = [NSString stringWithFormat:@"Rank: %@", (NSString *)[[[array objectForKey:@"leaderboards"] objectForKey:@"all"] objectForKey:@"position"]];            
            [TVWindow addSubview:rankLabelTV];

            levelNameLabelTV = [[UILabel alloc] initWithFrame:CGRectMake(222, 244, 441, 22)];
            levelNameLabelTV.backgroundColor = [UIColor clearColor];
            levelNameLabelTV.textColor = [UIColor whiteColor];
            if ((NSNull *)[value objectForKey:@"level"] == [NSNull null]) {
                levelNameLabelTV.text = @"No Level";
            } else {
                levelNameLabelTV.text = [NSString stringWithFormat:@"Level: %@", (NSString *)[[[array objectForKey:@"level"] objectForKey:@"definition"] objectForKey:@"name"]];
            }
            [TVWindow addSubview:levelNameLabelTV];

            pointLabel.text = [information stringForKey:@"pointString"];
            pointLabel.textAlignment = UITextAlignmentLeft;
            displayNameLabelTV.text = [information stringForKey:@"displayNameString"];
            displayNameLabel. text = [information stringForKey:@"displayNameString"];
            rankLabel.text = [information stringForKey:@"rankString"];
            levelLabel.text = [information stringForKey:@"levelString"];

            NSURL *url1 = [NSURL URLWithString: [NSString stringWithFormat:@"%@", (NSString *)[array objectForKey:@"picture_url"]]];
            NSData *urlData1 = [NSData dataWithContentsOfURL:url1];
            UIImage *image1 = [UIImage imageWithData:urlData1];
            profilePicture.image = image1; 
            profilePictureTV.image = image1;    

            [information setObject:[NSString stringWithFormat:@"%@", (NSString *)[luckyNumbers1 objectForKey:@"session"]] forKey:@"sessionID"];
        }}

    NSURLRequest *request2;
    request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@/api/widgets/%@/%@/players/%@/rewards.json", [information stringForKey:@"host"], [information objectForKey:@"apiKey"], [information objectForKey:@"URL"], [information objectForKey:@"userID"]]]];
    NSLog(@"Badges Request is: %@", request2);
    NSURLConnection *connection2;
    connection2 = [[NSURLConnection alloc] initWithRequest:request2 delegate:self startImmediately:YES];
    NSURLResponse *resp3;
    NSData *cData2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:&resp3 error:nil];
    NSString *cDataString2 = [[NSString alloc] initWithData:cData2 encoding:NSUTF8StringEncoding];
    [self getUsersBadges: cDataString2];       
    [[NSURLConnection alloc] initWithRequest:request2 delegate:self];
    //   pass cDataString into the JSON parser and update points

    [connection release];
}
  • 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-24T09:23:16+00:00Added an answer on May 24, 2026 at 9:23 am

    Without seeing your initialization of reponseData, it’s hard to be sure, but I would guess that you’re either declaring it as [NSMutableData data] (which will get autoreleased) or release/autoreleaseing it before you get to -connection:didReceiveResponse:. The solution is to make sure it doesn’t get released early, either by calling retain on it or by initializing it with [[NSMutableData alloc] init]. In either case, you’ll need to release it once you’re done, though it looks as if you’re doing that already in your -connectionDidFinishLoading:, so no change needed there.

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

Sidebar

Related Questions

Im making a async request but when I try to parse it with this
I am making heavy use of async requests by Javascript to the webserver. Since
I have some stuff written in c# that executes concurrent code, making heavy use
I'm experimenting with making async WCF calls. I'm looking at making multiple calls to
I've got an asp.net web page that is making 7 async requests to a
Making a request to a RESTful service in Silverlight with HttpWebRequest works well so
When making async WCF service calls, the service is able (and must) execute the
I insert a record into the database by making an async AJAX call. After
I log in users from a Http page via ajax. I'm making the request
After shamelessly pilfering a code snippet from Tomas Petricek's Blog: http://tomasp.net/blog/csharp-fsharp-async-intro.aspx Specifically, this one

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.