getting about:blank in shouldStartLoadWithRequest

2019-01-20 18:59发布

问题:

I am passing my data from javascript to objective-c. for that I am using IFRAME.
Here is my code:
context.html

function openCustomURLinIFrame(src)
{
    alert(src);
    var rootElm = document.documentElement;
    var newFrameElm = document.createElement("IFRAME");
    newFrameElm.setAttribute("src",src);
    document.documentElement.appendChild(newFrameElm);
    //remove the frame now
    newFrameElm.parentNode.removeChild(newFrameElm);
    newFrameElm = null;
}  

Indoor.m

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSLog(@"Loading: %@", [request URL]);
    NSURL *url = [request URL];
    NSString *urlStr = url.absoluteString;

    return [self processURL:urlStr];

}  

I am getting

Loading: about:blank

I am using xCode 8.2.1 it is working well in IOS 9.3 but not working in iOS 10.2.

Edit:
My alert screenshot in .html file.

Edit:
Method in html file in which I call openCustomURLinIFrame method.

function calliOSFunction(functionName, args, successCallback, errorCallback)
{
    var url = "js2ios://";
    var callInfo = {};
    callInfo.functionname = functionName;
    //alert("Custom menu clicked !!"+functionName);
    if (successCallback)
    {
        //alert("Success !!"+functionName);
        callInfo.success = successCallback;
    }
    if (errorCallback)
    {
        //alert("Error !!"+functionName);
        callInfo.error = errorCallback;
    }
    if (args)
    {
        //alert("args !!"+args);
        callInfo.args = args;
    } 
    url += JSON.stringify(callInfo)   
    openCustomURLinIFrame(url);
}

Help me to resolve this issue.

回答1:

Finally after long time I got my answer.

function calliOSFunction(functionName, args, successCallback, errorCallback)
{
    var url = "js2ios:///";   /* Added one more "/" */
    var callInfo = {};
    callInfo.functionname = functionName;
    //alert("Custom menu clicked !!"+functionName);
    if (successCallback)
    {
        //alert("Success !!"+functionName);
        callInfo.success = successCallback;
    }
    if (errorCallback)
    {
        //alert("Error !!"+functionName);
        callInfo.error = errorCallback;
    }
    if (args)
    {
        //alert("args !!"+args);
        callInfo.args = args;
    }

    url += JSON.stringify(callInfo)

    openCustomURLinIFrame(url);
}   

I add one more "/" in url variable.