Skip to content

Callbacks are ignored sometimes #9

@doubotis

Description

@doubotis

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;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions