Code=102“帧加载中断”当我将 NSstring 作为 html Iphone 加载时
我正在为 iphone/ipad 开发一个应用程序,但遇到一些问题。
我正在使用 html 代码动态构建 nsmutablestring 并将其作为 html 加载到 uiwebview 中。我还将本地 js 文件加载到这个 html 页面,其中有一些逻辑功能。 在此 html 中,我得到了一个表单,末尾有一个提交按钮。
我想做的是,点击提交按钮时,它将调用一个方法,将字符串返回到 Objective-C 代码。我对控制表单的 javascript 没有任何问题。但是,当单击提交按钮时,本机代码会给我
Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted" UserInfo=0x6c60b20 {NSErrorFailingURLKey=file://
我尝试在 js 函数中重定向,如 window.location="myapp:custom:"+string;但我遇到了同样的问题。甚至尝试像 JSBridge api 这样的库。
我怀疑这是因为我正在将 NSString 加载到 webview 中,该 webview 具有用于加载本地 js 文件的 mainbundle 路径的 baseUrl 。
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[self.webView loadHTMLString:string baseURL:baseURL];
I am developing an app for iphone/ipad that I have some problems with.
I am building dynamically a nsmutablestring with html code and loading as html to a uiwebview. I also load a local js file to this html page where I have some logical functions.
In this html I got a form with a submit button at the end.
What I am trying to do is that at the moment the submit button is click, it will call a method that return a string back to the objective-c code. I have no problem with the javascript controlling the form. But when the submit button is click, the native code gives me
Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted" UserInfo=0x6c60b20 {NSErrorFailingURLKey=file://
I have tried to redirect in js-function like window.location="myapp:custom:"+string; But I got the same problem. Even trying libraries like JSBridge api.
I suspect that is because I am loading a NSString to the webview that has the baseUrl the mainbundle path for loading the local js-file.
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[self.webView loadHTMLString:string baseURL:baseURL];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只需要用 html 代码中的输入按钮更改输入提交即可。所以现在我将字符串从 javascript 返回到 Objective-C。
I only had to change the input submit with a input button in the html code and works. So now I got the string from javascript back to objective-c.