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
基础教程推荐
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
