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

查看:903
本文介绍了在IOS 10中使用IFRAME将数据从javascript传递到objective-c时,在ShouldStartLoadWithRequest中获取: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.

编辑:

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

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

我在网址中再添加一个/变量。

I add one more "/" in url variable.

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

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