在 IOS 10 中使用 IFRAME 将数据从 javascript 传递到 Objective-c 时,在 shouldStartLoadWithRequest 中获取 about:blank [英] getting about:blank in shouldStartLoadWithRequest while passing the data from javascript to objective-c using IFRAME in IOS 10

查看:30
本文介绍了在 IOS 10 中使用 IFRAME 将数据从 javascript 传递到 Objective-c 时,在 shouldStartLoadWithRequest 中获取 about:blank的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的数据从 javascript 传递到 Objective-c.为此,我正在使用 IFRAME.
这是我的代码:
context.html

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

}  

我来了

加载中:about:blank

Loading: about:blank

我使用的是 xCode 8.2.1,它在 IOS 9.3 中运行良好,但在 iOS 10.2 中无法运行.

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


我在 .html 文件中的警报屏幕截图.


My alert screenshot in .html file.


我在其中调用 openCustomURLinIFrame 方法的 html 文件中的方法.


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

帮我解决这个问题.

推荐答案

终于在很久之后得到了答案.

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

我在 url 变量中再添加一个/".

I add one more "/" in url variable.

这篇关于在 IOS 10 中使用 IFRAME 将数据从 javascript 传递到 Objective-c 时,在 shouldStartLoadWithRequest 中获取 about:blank的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆