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

Success block called before dismissing web view. #191

Closed
matheusbrat opened this issue Nov 16, 2015 · 1 comment
Closed

Success block called before dismissing web view. #191

matheusbrat opened this issue Nov 16, 2015 · 1 comment
Labels
bug This points to a verified bug in the code

Comments

@matheusbrat
Copy link

On fetchUserProfileWithIdToken:token the success block is called before dismissing the web view, if our success block needs to present some view controller it will not be able to present it, because the web view is on top of the view hierarchy causing an error.

We tried to execute [self dismiss] before calling the success block and it worked. Is there any reason to call the success block before dismissing the web view?

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    A0LogVerbose(@"Loading URL %@", navigationAction.request.URL);
    NSURLRequest *request = navigationAction.request;
    NSURL *url = request.URL;
    BOOL isCallback = [self.authentication validateURL:url];
    if (!isCallback) {
        decisionHandler(WKNavigationActionPolicyAllow);
        return;
    }
    NSError *error;
    A0Token *token = [self.authentication tokenFromURL:url error:&error];
    if (token) {
        A0IdPAuthenticationBlock success = self.onAuthentication;
        @weakify(self);
        [self showProgressIndicator];
        [self.client fetchUserProfileWithIdToken:token.idToken success:^(A0UserProfile *profile) {
            @strongify(self);
            if (success) {
                success(profile, token);
            }

            decisionHandler(WKNavigationActionPolicyCancel);
            [self dismiss];
        } failure:^(NSError *error) {
            @strongify(self);
            [self handleError:error decisionHandler:decisionHandler];
        }];
    } else {
        [self handleError:error decisionHandler:decisionHandler];
    }
}
@hzalaz
Copy link
Member

hzalaz commented Nov 16, 2015

No reason at all, I have a similar issue with some type of errors that will show an alert so they are probably related. I am thinking of using dispatch_async in the main queue to enforce it and avoid switching them in code by accident in the future

@hzalaz hzalaz added the bug This points to a verified bug in the code label Nov 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This points to a verified bug in the code
Projects
None yet
Development

No branches or pull requests

2 participants