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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:12:49+00:00 2026-06-14T18:12:49+00:00

my app is using network connections as in here: – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

  • 0

my app is using network connections as in here:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 
    .
    .
    .
    receivedData = [[NSMutableData alloc] init];
}

.

-(void) dataFromWeb{
request = [[NSURLRequest alloc] initWithURL: url];
theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

if (theConnection) {
    receivedData = [[NSMutableData data] retain];
    NSLog(@"** NSURL request sent !");
} else {

    NSLog(@"Connection failed");
}

.

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    .
    .
    .
    [theConnection release];
    [request release];

// Here - using receivedData
[receivedData release];
}

.

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

.

- (void)connection:(NSURLConnection *)connection
  didFailWithError:(NSError *)error
{
    [theConnection release];
    [request release];
    [receivedData release];
}

.

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

. Down the road in the app is this snippet (onButtonPressed):

if (theConnection) {
    // Create the NSMutableData to hold the received data.
    // receivedData is an instance variable declared elsewhere.
    receivedData = [[NSMutableData data] retain];
} else {
    NSLog(@"Connection failed");
}

What I want to understand is:

  • If I wanted to create another simultaneous URLRequest, would I need to use a different connection so that data arriving from the web won’t mix up upon retrieval?

  • In this code, what happens is that sometimes the code would crash on the line of the function didReceiveResponse() setLength:0, when the app crashed I saw receivedData=nil should I change the line to

    if(receivedData!=nil)
       [receivedData setLength:0];
    else
       receivedData = [[NSMutableData data] retain];
    
  • I am not so sure what this line is doing receivedData = [[NSMutableData data] retain];

  • 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-14T18:12:50+00:00Added an answer on June 14, 2026 at 6:12 pm

    I think that the easiest way to handle 2 connections is duplicating the NSMutableData. I use in that way, and it works perfectly for me.

    Fist you do this in the point you want the second connection:

    receivedData2 = [[NSMutableData alloc] init];
    
    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response  
    {  
        if (receivedData2) {
            [receivedData2 setLength:0];  
        }
        else 
        {
            [receivedData setLength:0];  
        }
    }  
    
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data  
    {  
        if (receivedData2) {
            [receivedData2 appendData:data];  
        }
        else {    
            [receivedData appendData:data]; 
        }
    } 
    

    And then, in the method you ask for receivedData2 or receivedData

    And when you use it don´t forget to do:

    receivedData2=nil;
    [receivedData2 setLength:0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an app using jquery mobile and last issue to be solved
I am creating an app using iOS 5 SDK. I managed to push views
I am developing a app using Monodroid (C#) and wanted to some good looking
I have a Sinatra app using Rack::Session::Cookie use Rack::Session::Cookie, :key => 'my.key', :path =>
I have a PhoneGap App using jQuery Mobile. At a certain page, I cannot
I built my app using Grails 2.0.4 and tested it in Jetty. In Jetty
I'm developing an app using Silverlight control for Bing Maps . User can search
I made an app using contact sync. I list the following contact info with
I done computing intensive app using OpenCV for iOS . Of course it was
I'm developing web app using Spring Integration to route my messages, but I have

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.