UIWebView在网页加载时显示错误,Safari显示完美
问题是网站在 UIWebView 中无法完全加载,但在 Safari 中可以正常加载。
这是我在 UIWebView 中加载网站时遇到的错误:
警告: cos_before_render(/home/user/ctown/doc_wbn//../sys/swt/www.westspringsec.moe.edu.sg.mob) [function.cos-before-render]:失败 打开流:没有这样的文件或 目录在 /home/user/ctown/cti_bin/wbn/cos_init.inc 在第 731 行
警告:cos_before_render() [function.include]:打开失败 '/home/user/ctown/doc_wbn//../sys/swt/www.westspringsec.moe.edu.sg.mob' 纳入 (include_path='.:/home/user/ctown/cti_bin/phplot:/usr/local/lib/php') 在 /home/user/ctown/cti_bin/wbn/cos_init.inc 在线 731
致命错误:调用未定义 函数: json_encode() 中 /home/user/ctown/cti_bin/wbn/cos_init.inc 在线 737
- (void)viewDidLoad {
NSString *urlAddress = @"http://www.westspringsec.moe.edu.sg";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[Webview loadRequest:requestObj];
[super viewDidLoad];
}
我尝试了下面链接的问题,但是我无法修改网站的后端!
The problem is that the website doesn't fully load in a UIWebView, but it loads normally in Safari.
This is the error I get when loading the website in a UIWebView:
Warning:
cos_before_render(/home/user/ctown/doc_wbn//../sys/swt/www.westspringsec.moe.edu.sg.mob)
[function.cos-before-render]: failed
to open stream: No such file or
directory in
/home/user/ctown/cti_bin/wbn/cos_init.inc
on line 731Warning: cos_before_render()
[function.include]: Failed opening
'/home/user/ctown/doc_wbn//../sys/swt/www.westspringsec.moe.edu.sg.mob'
for inclusion
(include_path='.:/home/user/ctown/cti_bin/phplot:/usr/local/lib/php')
in
/home/user/ctown/cti_bin/wbn/cos_init.inc
on line 731Fatal error: Call to undefined
function: json_encode() in
/home/user/ctown/cti_bin/wbn/cos_init.inc
on line 737
- (void)viewDidLoad {
NSString *urlAddress = @"http://www.westspringsec.moe.edu.sg";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[Webview loadRequest:requestObj];
[super viewDidLoad];
}
I tried the question linked below, however I can't modify the backend of the website!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
错误不在您的代码中! UIWebView,特别是在模拟器中,使用如下用户代理:
Mozilla/5.0(iPhone Simulator;U;CPU iPhone OS 4_2,如 Mac OS X;en-us)AppleWebKit/533.17.9(KHTML,如 Gecko)Mobile /8C134
当您调用该 url 时,它会导致您看到的错误。这是服务器端错误。
您可以使用此代码更改您的用户代理,将其放在应用程序启动阶段的某个位置,这样它只设置一次:
有了这个,我就可以打开您的页面。看起来该网站为 iPhone 返回了不同的标记,因此上面代码的结果将显示该网站,对于小显示屏来说有点大。
The error is not within your code! The UIWebView, especially from within the simulator uses a user agent something like this:
Mozilla/5.0 (iPhone Simulator; U; CPU iPhone OS 4_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8C134
When you call the url provided it results in the error you are seeing. It's a server side error.
You can alter your user agent by using this code, put it somewhere in the startup phase of your app so it's only set once:
With this I was able to open your page. It looks like the site returns different markup for the iphone, so the result with the code above will show the website, which is a bit large for the small display.
UIWebView 和 Safari 没有相同的用户代理。
UIWebView and Safari does not have the same user agent.
这个答案不会解决您的问题(请参阅尼克的答案),但您应该在执行其他操作之前放置
[super viewDidLoad];
。所以:This answer won't fix your issue (see Nick's answer), but you should put
[super viewDidLoad];
before you do anything else. So: