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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:34:22+00:00 2026-06-09T16:34:22+00:00

whem my app starts for the first time I need to copy some (

  • 0

whem my app starts for the first time I need to copy some ( arround 300-400 images ) to the documents folder. What I see is that it takes tool long (even thought now Im testing only with just 30-40 images). At the begining my app crashed when running on the phone (not on simulator) because it took too long to run. Now I’m running the method that copies all files on a thread. The app stays up, but I think that ios kill that thread after a few seconds. Should I have each image copy on a new thread???

My code is like this: (this is the part that runs in the thread)

-(void) moveInitialImagesFromBundleToDocuments {
//move all images.

    NSMutableArray *images = [MyParser getAllImagesList];
    for (int i = 0 ; i< [images count] ; i++) {
        [self copyFileFromBundleToDocuments:[images objectAtIndex:i]];
    }
}

- (void) copyFileFromBundleToDocuments: (NSString *) fileName {

    NSString *documentsDirectory = [applicationContext getDocumentsDirectory];
    NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
    NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:fileName];
    NSLog(@"Source Path: %@\n Documents Path: %@ \n Destination Path: %@", sourcePath, documentsDirectory, destinationPath);

    NSError *error = nil;

    [self removeFileFromPath:destinationPath];


    [[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:destinationPath error:&error];

    NSLog(@"File %@ copied", fileName);
    NSLog(@"Error description-%@ \n", [error localizedDescription]);
    NSLog(@"Error reason-%@", [error localizedFailureReason]);
}

Any suggestions? First to make copying faster and second, should I make a new thread for each file I copy?


Comment 1:

This looks nice. But I would like to dim the application so the user will not be able to use the appication untill all images are loaded.

I run this methods under . It does stop the user from being able to run the application, but I think that on the phone , the thread is beeing killed because when I tried it , it took too long loading. Never stopped actualluy.

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText = @"preparing...";
hud.dimBackground = YES;
hud.square = YES;
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    // Do something...

    FileUtil *fileut = [[FileUtil alloc] init];
    [fileut moveInitialImagesFromBundleToDocuments];

    //Done something

    dispatch_async(dispatch_get_main_queue(), ^{
        [MBProgressHUD hideHUDForView:self.view animated: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-06-09T16:34:23+00:00Added an answer on June 9, 2026 at 4:34 pm

    When calling the method, I suggest you to use GCD to move this to a background thread, so you could call the whole for cycle like this. (I also changed a little bit your for cycle to make it simple.

    -(void) moveInitialImagesFromBundleToDocuments
    {
    //move all images and use GCD to do it
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
        NSMutableArray *images = [MyParser getAllImagesList];
            for (id image in images) {
                [self copyFileFromBundleToDocuments:image];
            }
        });
    }
    

    Regarding to make the copying faster, I don’t know of any solution.

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

Sidebar

Related Questions

When app is in foreground, even if I set the applicationBadgeNumber to 0, when
A read some posts here and google and don´t find a substancial answer. Supose
How can I stop a timer inside..(lets say form1) whem im in form2? i
I need to map my database IDs with NSDictionary or NSArray. I have a
Hello I need your help on the following problem. I am parsing the file
I'm Trying, pass a long array for a named query (native SQL) for to
Suddenly, all my ASP.NET LinkButtons (that use the href=javascript:__PostBack... syntax) stopped working for all
I'm setting up a build server using NAnt (and CruiseControl.NET) and I'm currently writing
Well something is wrong but i dont know what. I cannot delete a row
I work a lot with serial communications with a variety of devices, and so

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.