我解决了 查看下面的选定答案!
我一直在努力寻找导致OSX Cocoa应用程序的WebView与Safari行为不同的原因。事实证明,用户代理是不同的(很明显吗?),而我访问的网站不知道该如何处理。
令人惊讶的是,它是https://messenger.com(facebook聊天)。
问题是它没有在屏幕上显示图片。它会加载,但实际上不会显示。看看这个..
如果您查看我编号为“ 2”的区域,则会看到空白区域。我没有审查。它只是空的。
So here's my original question link: Simple Swift Cocoa app with WebKit: Upload picture doesn't work
I solved the first issue (thanks to the answers :D), but second issue persists.
To debug this, I opened the Inspect Element and I found this out.
<body class=" webkit-legacy webkit mac x1 body_textalign Locale_en_US _z4_" dir="ltr">
When I did load the exact same page from Safari, I'd see this:
<body class="safari webkit mac x1 body_textalign Locale_en_US _z4_" dir="ltr">
So I decided to replace that line from WebView of my app, and viola! it works! so...
I tried to find some methods to set up my user agent to Safari, but I can't get this to work. Any suggestion please?
如所承诺的,这就是答案。
我在ViewController
类中添加了此功能。
func webView(sender: WebView!, didFinishLoadForFrame frame: WebFrame!) {
webView.stringByEvaluatingJavaScriptFromString("document.body.className = 'safari webkit mac x1 Locale_en_US _z4_';")
}
很简单,但是工作得很好。
我仍然对应用程序本身有一些问题(例如,“下载图像”按钮不会触发文件浏览器对话框),但是诸如
工作很好。
我正计划为此
如果您有兴趣帮助我,请发表评论!
感谢你的帮助 :)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句