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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:32:10+00:00 2026-06-13T07:32:10+00:00

I have an import sequence that reads from an archive, unzips the containing files

  • 0

I have an import sequence that reads from an archive, unzips the containing files and creates corresponding core data entities for each. This entire process happens in the background and a separate context has been created for each thread etc. so it all works fine.

It turns out that a desirable feature of this particular import sequence is that we allow any of the input files to be password protected (there are several of them included in an archive) so I need to check whether a file is password protected in which case the user will be prompted to enter the password via a UIAlertView.

This is where my problem starts.

I send the UIAlertView prompt to the main thread as I should, assign my Importer object as the delegate and wait for the user input.

When the user enters the password and taps OK/Cancel the delegate callback is still on the main thread so I am unable to manipulate my corresponding core data entity anymore without a lot of work (i.e. storing references to the managed object ID etc, creating new context etc).

My question:

Is it possible to go back my original background thread where the import process is working? How would I go about it?

Thanks,
Rog

  • 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-13T07:32:11+00:00Added an answer on June 13, 2026 at 7:32 am

    I’d try using a dispatch semaphore. Save it in an instance variable.

    @interface MyClass ()
    {
        dispatch_semaphore_t dsema;
    }
    @end
    

    Then, in the background thread method:

    // this is the background thread where you are processing the archive files
    - (void)processArchives
    {
        ...
        self.dsema = dispatch_semaphore_create(0);
        dispatch_async(dispatch_get_main_queue(), ^{
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: @"Title"
                                                                    ...
                                                               delegate: self
                                                                    ...
            ];
            [alertView show];
        });
    
        dispatch_semaphore_wait(self.dsema, DISPATCH_TIME_FOREVER);
        // --> when you get here, the user has responded to the UIAlertView <--
    
        dispatch_release(self.dsema);
        ...
    }
    

    The UIAlertView will invoke this delegate method:

    // this is running on the main queue, as a method on the alert view delegate
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        // do stuff with alertView
        if (buttonIndex == [alertView firstOtherButtonIndex]) {
            ...
            // when you get the reply that should unblock the background thread, unblock the other thread:
            dispatch_semaphore_signal(self.dsema);
            ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to import data from an Excel file to database and to do
in dirA/SConscript I have: Import('env') probeenv = env.Clone() probeenv['CXXFLAGS'] += ['-fno-rtti','-Wnon-virtual-dtor'] ... stuff that
I have to import some XML data into my app. Now I open a
Lets assume that we have PyV8: import PyV8 ctxt = PyV8.JSContext() and a python
That's what I have : Class A : #import ppCore.h @interface ppApplication : NSApplication
So I have a file that looks like so: #!/usr/bin/python import MySQLdb import subprocess
I have made a program that gets some strings in input from the user
What I have is a long list of codes that involves reading different files
I have a non-wcf server that I call from WCF client and I need
I have implemented a code that generate the infinite sequence given the base case

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.