Xcode 中的 HTML5 和 javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23943750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML5 and javascript in xcode
提问by Bob van Luijt
I'm quite new to xcode, because I mostly work with JS and HTML5. I've decided to create a simple webview app that enables me to work with JS and HTML5 (going to put it on Github asap)
我对 xcode 很陌生,因为我主要使用 JS 和 HTML5。我决定创建一个简单的 webview 应用程序,使我能够使用 JS 和 HTML5(将尽快将其放在 Github 上)
Now my question is about accessing certian iPhone features that I cannot use in Safari or Chrome (the reason why I'm creating this). So the question is: is this possible? for example, I can't access the camera (as a fullscreen background I mean) in an iOS browser, but can I use it in webview?
现在我的问题是关于访问我无法在 Safari 或 Chrome 中使用的特定 iPhone 功能(我创建它的原因)。所以问题是:这可能吗?例如,我无法在 iOS 浏览器中访问相机(我的意思是作为全屏背景),但我可以在 webview 中使用它吗?
采纳答案by daniel.gindi
You need any method of communicating between UIWebView and the containing app. There arelibraries out there that do just that, some better some less. In case you do not want them... So to outline the techniques to do that:
您需要在 UIWebView 和包含应用程序之间进行通信的任何方法。有一些图书馆可以做到这一点,有些更好一些。如果你不想要它们......所以要概述这样做的技术:
- App talking tothe webView - using
[webView stringByEvaluatingJavaScript:...]
- Webview talking to the app - using url directives. Which is essentialy
window.location = ...
with custom fake urls, and then parsing the NSURLs in the delegate methodwebView:shouldStartLoadWithRequest:navigationType:
and of course returningNO
to prevent actually navigating to your fake urls.
- 应用交谈到web视图-使用
[webView stringByEvaluatingJavaScript:...]
- Webview 与应用程序对话 - 使用 url 指令。这对于
window.location = ...
自定义假网址来说是必不可少的,然后在委托方法中解析 NSURLwebView:shouldStartLoadWithRequest:navigationType:
,当然返回NO
以防止实际导航到您的假网址。
If you find that you are missing consecutive URL requests, you could write a JS function that takes the URLs, puts them all in an array, pops one by one and sending them to the browser in a setTimeout(..., 0)
.
如果您发现缺少连续的 URL 请求,您可以编写一个 JS 函数,该函数接受这些 URL,将它们全部放在一个数组中,一个一个弹出并以setTimeout(..., 0)
.
回答by Nitish Dhar
You need to use something like this - Cordovaor PhoneGap( Both are the same thing )
你需要使用这样的东西 - Cordova或PhoneGap(两者都是一样的)
"Apache Cordova is a set of device APIs that allow a mobile app developer to access native device function such as the camera or accelerometer from JavaScript. Combined with a UI framework such as jQuery Mobile or Dojo Mobile or Sencha Touch, this allows a smartphone app to be developed with just HTML, CSS, and JavaScript."
“Apache Cordova 是一组设备 API,允许移动应用程序开发人员从 JavaScript 访问本机设备功能,例如相机或加速度计。结合 jQuery Mobile 或 Dojo Mobile 或 Sencha Touch 等 UI 框架,这允许智能手机应用程序仅使用 HTML、CSS 和 JavaScript 进行开发。”
Here is a description of all the device features cordova or phonegap allow you to use - Plugin API's
这是cordova 或phonegap 允许您使用的所有设备功能的描述-插件API