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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:43:30+00:00 2026-06-01T21:43:30+00:00

When loading a document from iCloud, one must make a call to openWithCompletionHandler:^(BOOL success)completionHandler

  • 0

When loading a document from iCloud, one must make a call to

openWithCompletionHandler:^(BOOL success)completionHandler

This function will start a background thread that download the file from iCloud, and upon finishing the load, runs the completion handler.

While that’s happening, any code after this call continues running.

How can I stop the program from continuing to run until after the download is complete?

Immediately after making a call to load from the cloud, my code tries to use the document – but of course, since it isn’t finished downloading, the code crashes.

Details follow:

I’m currently working on a save-file library to handle saving/loading of files, encryption, compression, and iCloud support. Users make a call to my library function LoadFileAtPath and there is a parameter specifying if they want me to check iCloud for this particular file.

When the function starts and I am meant to check on iCloud, the first thing I do is make a call to my iCloudload function, like so:

bool cloudLoad = [iCloudStorageManager readFileFromiCloud:filePath name:fileName];

within this function I make the call to openWithCompletionHandler, like so:

if ([fileManager fileExistsAtPath:[docURL path]]) 
        {
            [doc openWithCompletionHandler:^(BOOL success){
                if (!success) 
                {
                    // Handle the error.
                    NSLog(@"Failed to retrieve document:%@ from iCloud URL:%@.", fileName, [docURL absoluteString]);
                }
                else
                {
                    NSLog(@"Replacing document in sandbox with iCloud version");
                    BOOL* dir = nil;
                    if (![fileManager fileExistsAtPath:filePath  isDirectory:dir])
                    {
                        NSError *fileError = nil;
                        if(![fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:&fileError])
                        {
                            NSLog(@"Error creating file directory: %@\n%@\n%@\n%@", [fileError localizedDescription], [fileError localizedFailureReason], [fileError localizedRecoveryOptions], [fileError localizedRecoverySuggestion]);
                        }

                    }
                    // save new data if success
                    [iCloudStorage replaceDocumentInSandboxWith:doc newData:doc.loadedContents];
                }
            }];
            [doc release];
        }

After that, my code continues by trying to pull up the data, and do various things with it such as decrypt, decompress, and hand the file data to the caller.

My current (hacky) solution was to have, after the initial call to readFileFromiCloud, an loop that checks a bool, like so:

while (!cloudDidFinishLoad) 
{
     sleep(10);
}

This bool is initialized to false, and within the function seen above “replaceDocumentInSandboxWith”, the bool is set to true.

However, I have found that this causes the program to hang, it never finishes loading the iCloud file, and the completion handler never gets called.

I’m at a loss as to what I should do. I need the program to stop running code until the download is finished, but I don’t know how to do this.

  • 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-01T21:43:31+00:00Added an answer on June 1, 2026 at 9:43 pm

    Not sure if you found an answer to this or not, but what I would do is create a protocol for your library and then set up a delegate that you can make a call to when the completion handler finishes.

    Then in your main controller can be set up as the delegate and once the file is ready you can receive the call from the library that the file is ready to use. So the pseudo code would be something like this…

    1. Create iCloudStorageManager
    2. Set self as delegate of iCloudStorageManager
    3. Call the file open on the iCloudStorageManager
    4. Do whatever you need to do here, set up activity indicator or lock out the interface or neither and just assume it worked unless the delegate tells you it didn’t. Basically here your block will end and when the delegate function is called your main controller will pick back up control of the interface.

    5. In the delegate function you will receive the status from the iCloudStorageManager of whether it was successful or not. Once you get that call from the iCloudStorageManager you can free up the interface, post an alert that things went well or that things went south and offer a reply…whatever you want to do.

    But that is the way I would handle it. (Yes this is an old question, but I felt like I had some insight :))

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

Sidebar

Related Questions

//deep linking $.fn.ajaxAnim = function() { $(this).animW(); $(this).html('<div class=load-prog>loading...</div>'); } $(document).ready(function(){ contM = $('#main-content');
After loading a PHP template (using jQuery's load function), this simple script won't make
while loading getfptex(got it from CTAN) batch file ,when i'm extracting this batch file
In my web application I call a document can be huge. This document is
I had an XMLDocument loading a document from a server with no problems till,
I have a jquery ui loading bar: $(document).ready(function() { $(#progressbar).progressbar({ value: 37 }); });
I'm struggling with the asset pipeline. I'm loading dojo from Google CDN putting this
If I'm loading a WebView with an HTML document directly (no web server) using
In the DOM I am loading a static Google Map image. When the document
The following java-script is working fine (Jquery) $(document).ready(function(){ $('#c_area').load($('.m_top:first').attr('href')) }); $('.m_top').click( function(){ $(#myDiv).html('<img src=images/loading.gif

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.