Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

getting about:blank in shouldStartLoadWithRequest while passing the data from javascript to objective-c using IFRAME in IOS 10

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.
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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...