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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:24:28+00:00 2026-05-31T18:24:28+00:00

I am currently using a function in my app’s didFinishLaunchingWithOptions that retrieves a file,

  • 0

I am currently using a function in my app’s didFinishLaunchingWithOptions that retrieves a file, saves it to the application directory.

I have found that when there is a weak connection the app will crash when this is happening. I read that there is a 20 second time limit Apple allows before crashing the app. Is this correct? If so, I believe this is causing my issue as the app works flawlessly with the exception of being on a very weak connection.

How could I modify my logic below to try and compensate for this?

- (void)writeJsonToFile
{   
//applications Documents dirctory path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

//live json data url
NSString *stringURL = @"http://link-to-my-data.json";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];

//attempt to download live data
if (urlData)
{   
    NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"data.json"];
    [urlData writeToFile:filePath atomically:YES];
}
//copy data from initial package into the applications Documents folder
else
{
    //file to write to
    NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"data.json"];

    //file to copy from
    NSString *json = [ [NSBundle mainBundle] pathForResource:@"data" ofType:@"json" inDirectory:@"html/data" ];
    NSData *jsonData = [NSData dataWithContentsOfFile:json options:kNilOptions error:nil];

    //write file to device
    [jsonData writeToFile:filePath atomically:YES];
}

}

  • 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-31T18:24:29+00:00Added an answer on May 31, 2026 at 6:24 pm

    It’s a very bad idea to run this sort of thing on the main thread: I assume you are – basically, you’ll block the entire UI while you wait for the network operation to complete.

    dataWithContentsOfURL is not a good idea for this sort of thing. It will be much better to use NSURLConnection or one of the wrapper libraries like AFNetworking, because you can handle cases like when the connection times out gracefully.

    These libraries also have built-in methods to asynchronously download the data, which prevents the main UI thread from being locked.

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

Sidebar

Related Questions

I'm writing an application, and I'm currently using libcurl. The libcurl callback function works
Is there any way for using an annotation for running a function before currently
I have a funciton that I am currently using to show a hidden div.a_type
I'm currently using commons-net library for FTP client in my app. I have to
I have a simple mobile app in Titanium that I'm using to debug the
I have a database that is currently using AES 128. The database has about
I'm currently using the toprettyxml() function of the xml.dom module in a Python script
Here is the code I'm currently using: $.ajax({ success: function(){ $('.post_container').append('test <br />'); }
Currently i am using DWS CreateFolder function to create folder on Sharepoint (using C#).
Currently, I am using this function: function tokenize( str ) local ret = {}

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.