0

I have created a password protected app. The app is allowed to run in background. When it returns to foreground, I display an alert to prompt the user for password, by overriding the applicationWillEnterForeground: method in appdelegate like so-

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    if (/*password is enabled*/)    {
        alertview = [[UIAlertView alloc] initWithTitle:@"LOGIN"
                                               message:@"Enter app password"
                                              delegate:self
                                     cancelButtonTitle:nil
                                     otherButtonTitles:nil];
        alertview.alertViewStyle = UIAlertViewStyleSecureTextInput;
        pwdTF = [alertview textFieldAtIndex:0];
        [pwdTF setDelegate:self];
        [alertview show];
    }

}

However, the alert takes a little time to appear. During this time, the view remains vulnerable.

Is there a way to make uialertview show instantly?

Zaxter
  • 2,939
  • 3
  • 31
  • 48
  • You can just try to present alert on main thread for this. – Ashutosh Jul 15 '14 at 13:46
  • Ashutosh, I'm quite a newbie to ios programming. Could you please provide me a link or example as to how an alert can be presented on the main thread when the app returns to foreground? – Zaxter Jul 16 '14 at 05:52

1 Answers1

5
dispatch_async(dispatch_get_main_queue(), ^{
    <# Write UI related code to be executed on main queue #>
});
Ashutosh
  • 2,215
  • 14
  • 27
  • Thanks for the prompt reply! If I understand it correctly, this block would go into the 'applicationWillEnterForeground:' appdelegate method in my case, right? – Zaxter Jul 16 '14 at 06:04