3

When starting, my app checks for an update. If it is available, I try to put an overlay view on top of each other with this instruction:

[[[UIApplication sharedApplication] keyWindow] addSubview:overlay];

The overlay view appears but quickly disappears, while I want to remove it when the update process ends. Instead, if I add the overlay view as a subview of the current view, the overlay view stays on top until the update process finishes.

I have to put the overlay view on top of keyWindows because my app has a tab bar, so if I put the overlay view on top of the current view, the overlay view will disappear if the user tap on another item in the tab bar.

May be due to the fact I moved the check for an update in a separate task with NSInvocation? Here is my relevant code:

[in viewDidLoad]

    NSOperationQueue *queue = [NSOperationQueue new];

    NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(checkForUpdate) object:nil];

    [queue addOperation:operation];
    [operation release];

[in checkForUpdate]

    if (![localVersion isEqualToString:remoteVersion])
    {
        [self performSelectorOnMainThread:@selector(doUpdate) withObject:nil waitUntilDone:NO];
    }

[in doUpdate]

UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"Update" message:@"Download the latest version of...?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];

[alertView show];
[alertView release];

[in willDismissWithButtonIndex]

if (buttonIndex == 1)
{
    CGRect overlayFrame = [[UIApplication sharedApplication] keyWindow].bounds;
    overlay = [[UIView alloc] initWithFrame:overlayFrame];
    overlay.backgroundColor = [UIColor blackColor];
    overlay.alpha = 0.7;

    // Do other staff...

    [[[UIApplication sharedApplication] keyWindow] addSubview:overlay];

    NSURL *url = [NSURL URLWithString:@"http:www.testserver.com/test/UpdatePack.zip"];
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:300.0];

    connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    connection = nil;
}

[in connectionDidFinishLoading]

[overlay removeFromSuperview];

1 Answer 1

3

I solved the problem adding the overlay to the tabbarViewController's view:

[self.tabBarController.view addSubview:overlay];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.