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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:38:49+00:00 2026-05-31T21:38:49+00:00

Will [NSData dataWithContentsOfURL:url] either return the full amount of bytes on success, or nil

  • 0

Will [NSData dataWithContentsOfURL:url] either return the full amount of bytes on success, or nil if something goes wrong?

Is there a chance, that it would return maybe only half of the bytes of the content… perhaps if their internet connection fails halfway through?

If there is a chance that it would return only partial data, is there some other function I could use that would be more reliable and I would be able to know definitely whether they got the full amount of data or not?

  • 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-31T21:38:50+00:00Added an answer on May 31, 2026 at 9:38 pm

    I’m not sure about the implementation of -dataWithContentsOfURL: but using a sychronous method like this is not really recommended anyway.

    Something based on NSURLConnection is your best bet, but you need to be aware of a few things. Most people don’t realize that if the server disconnects while an NSURLConnection is receiving data, it will not cause the download to fail with an error. The -connectionDidFinishLoading: delegate method will be called as normal. Many people get this wrong.

    If you want to be sure you have all the data, you need to handle the -connection:didReceiveResponse: delegate method and save the value of [response expectedContentLength]. Then in -connectionDidFinishLoading: you can make sure you received the same number of bytes as expected, and generate an error if not.

    There are many free libraries out there based on NSURLConnection like AFNetworking. However you need to beware of bad code. I’ve just checked the source to AFNetworking and it appears they also do not check for the case where the server sends back less data than the Content-Length header specifies. Also note that the popular ASIHTTPRequest is no longer being actively developed and has received some criticism over its implementation.

    I’ll leave it up to others to suggest other alternative libraries, but NSURLConnection is the right direction.

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

Sidebar

Related Questions

i wrote the following code : NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString
I create a NSData and use the function - (const void *)bytes; So, it
I'm using [NSData dataWithContentsOfURL:] to create two NSData instances and I want to compare
imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:srcAddres]]; Downloading jpeg to my imagedata will spend some
I have a url that is a link to an audio file and will
The first time i call this method file1 will be nil and file2 will
I've an NSData object, the length is 4 bytes .These four bytes i'm extracting
I have these codes: UIImage * img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:IMAGEURL]]]; [self.imageView
Will limiting a query to one result record, improve performance in a large(ish) MySQL
Will the code below work if the clock on the server is ahead of

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.