Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't present safari view controller inside action handler block #60

Open
bbehradd opened this issue Dec 30, 2018 · 2 comments
Open

Can't present safari view controller inside action handler block #60

bbehradd opened this issue Dec 30, 2018 · 2 comments

Comments

@bbehradd
Copy link

bbehradd commented Dec 30, 2018

I want to show a alert view to user and after pushing action button present safari viewController
but it wont present.
if i run same code without action handler block, it works very well.
I think the problem is in action handler block.

id DoLogOutAct = ^(LGAlertView *alertView, NSString *title, NSUInteger index) {
        if(index==0){

            NSURL *url = [[NSURL alloc]initWithString:@"http://google.com"];
    SFSafariViewController *safari = [[SFSafariViewController alloc]initWithURL:url];
    [self presentViewController:safari animated:NO completion:nil];
        }
    };
    [Functions showAllert:NSLocalizedString(@"LogOut", @"") Content:NSLocalizedString(@"AreYouSureExitApp", @"") ContentView:nil Buttons:[NSArray arrayWithObject:NSLocalizedString(@"LogOut", @"")] ArrayAction:DoLogOutAct CancelButton:NSLocalizedString(@"NeverMind", @"") CancelAction:nil];
+(LGAlertView *)showAllert:(NSString *)title Content:(NSString *)msg ContentView:(UIView *)cntview Buttons:(NSArray *)ButtonTitle  ArrayAction:(id)actionsBlock CancelButton:(NSString *)cancelBTN CancelAction:(id)cancelAct{
    
    LGAlertView *alertView = [[LGAlertView alloc] initWithViewAndTitle:title
                                                               message:msg
                                                                 style:LGAlertViewStyleAlert
                                                                  view:cntview
                                                          buttonTitles:ButtonTitle
                                                     cancelButtonTitle:cancelBTN
                                                destructiveButtonTitle:nil
                                                         actionHandler:actionsBlock
                                                         cancelHandler:cancelAct
                                                    destructiveHandler:nil];
    
    [alertView setTitleFont:[UIFont fontWithName:NSLocalizedString(@"DefaultFontBold", @"") size:15]];
    [alertView setButtonsFont:[UIFont fontWithName:NSLocalizedString(@"DefaultFont", @"") size:14]];
    [alertView setButtonsBackgroundColor:[UIColor colorWithHexString:@"eee" withAlpha:.5]];
    [alertView setMessageFont:[UIFont fontWithName:NSLocalizedString(@"DefaultFont", @"") size:14]];
    [alertView setCancelButtonFont:[UIFont fontWithName:NSLocalizedString(@"DefaultFont", @"") size:14]];
    [alertView setCancelButtonBackgroundColor:[UIColor colorWithHexString:@"eee" withAlpha:.5]];
    [alertView showAnimated:YES completionHandler:nil];
    return alertView;
}
@Mahdimm
Copy link

Mahdimm commented Dec 30, 2018

Hi @bbehradd I got same problem and you can put thread on sleep
[NSThread sleepForTimeInterval:.2]; and it will work

@bbehradd
Copy link
Author

bbehradd commented Dec 30, 2018

hi @Mahdimm thanks for your answer.....yes it works well
but I don't think this is good idea to make Thread Sleep for a while!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants