getting about:blank in shouldStartLoadWithRequest while passing the data from javascript to objective-c using IFRAME in IOS 10(在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 IOS 10 中使用 IFRAME 将数据从 javascript 传递到 Objective-c 时,在 shouldStartLoadWithRequest 中获取 about:blank
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
