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

Callbacks are ignored sometimes #9

Open
doubotis opened this issue Feb 16, 2017 · 0 comments
Open

Callbacks are ignored sometimes #9

doubotis opened this issue Feb 16, 2017 · 0 comments

Comments

@doubotis
Copy link

doubotis commented Feb 16, 2017

It seems that sometimes, callbacks are ignored. It appears notably when we call multiple times the same interface method in a small gap of time.

This is caused by iframe loading in easyjs-inject.js :

iframe.setAttribute("src", "easy-js:" + obj + ":" + encodeURIComponent(functionName) + argStr);
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;

This triggers a call to (void)webViewDidStartLoad:(UIWebView *) in EasyJSWebViewProxyDelegate that reinjects again the EasyJS callback handling, resetting the EasyJS.__callbacks variable to an empty array, forgotting any other callbacks in progress.

Solved

Solved by injecting the EasyJS javascript stuff ONLY one time, by checking a boolean variable set to true when the javascript stuff is injected.

In the same method :

if (!_injectJSDone) {
        NSString* js = INJECT_JS;
        //inject the basic functions first
        [webView stringByEvaluatingJavaScriptFromString:js];
        //inject the function interface
        [webView stringByEvaluatingJavaScriptFromString:injection];
        
        _injectJSDone = YES;
    }
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

1 participant