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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:49:09+00:00 2026-05-25T06:49:09+00:00

Currently I am doing simple tests of my app (written in xCode for MAC

  • 0

Currently I am doing simple tests of my app (written in xCode for MAC OS X) and I noticed that there are some issues when it comes to getting data from internet. So I am requesting some text data:

NSString *dataFromInternet = [[NSString alloc] initWithContentsOfURL:url
                                                 usedEncoding:&encoding 
                                                        error:&error];

Now:

  1. If internet works then everything is awesome.

  2. If internet disconnected then I am getting error in “error” however “dataFromInternet” still returns the very same data as if there was internet connect

  3. If I request data (above code) while internet disconnected and then connect internet and request data once again, I am still getting error as if internet doesn’t work!

I don’t understand this behavior and what is going on. I can only guess there is some caching mechanism and I don’t now how to fix it.

Please explain this ( #2 & #3 ) odd behavior and how to fix it.
Thank you.

  • 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-25T06:49:09+00:00Added an answer on May 25, 2026 at 6:49 am

    Okay, so after sometime roaming around internet and trying to find answer to my question, here is what I came up with:

    NSString *dataFromInternet = [[NSString alloc] initWithContentsOfURL:url
                                                 usedEncoding:&encoding 
                                                        error:&error];
    

    Above code does seem to use cache. In order to get data from internet and not to have all issues that are posted in the question, you have to use different object.

    NSData* data = [[NSData alloc] initWithContentsOfURL:url options:NSUncachedRead error:&error];
    NSString *dataFromInternet = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    

    What is happening in above sample code? You get data from internet almost the same way as you would with NSString except you specify following: “options:NSUncachedRead” – meaning that it will not cache the data and read always the latest and greatest – under condition that internet works.

    Once you obtained data you can convert it into NSString if desirable. I needed NSString so I converted it back to what I want. Otherwise all of issue in original post are solved!

    I can turn off airport on my mac and no data will be received and as soon as I turn on airport, data is flowing again. Very simple and works great for me.

    Thank you.

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

Sidebar

Related Questions

I need some help with rally. I'm currently looking at creating a simple app
I am doing some simple sanity validation on various types. The current test I'm
I'm currently doing some GUI testing on a ASP.net 2.0 application. The RDBMS is
i'm currently doing some reports for SSRS, and i just confirm what i already
I am currently doing some socket programming using C/C++. To be able to use
I'm currently doing something like this in some code I'm working on right now:
We're currently doing some Word automation, and want to be able to insert a
I am currently working on some personal tests and benchmarks to compare the workflow
I am currently writing an app on the Blackberry to do a simple send
I'm currently doing some research on smali/code obfuscator and I'm trying to get familar

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.