Xcode PhoneGap navigator.connection 未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17862136/
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
Xcode PhoneGap navigator.connection Undefined
提问by chadiusvt
Trying to port my PhoneGap javascript code into Xcode for debugging in iOS. Using Cordova-3.0.0.
尝试将我的 PhoneGap javascript 代码移植到 Xcode 中以在 iOS 中进行调试。使用 Cordova-3.0.0。
When I call:
当我打电话时:
navigator.connection.type
I am getting an 'undefined' for navigator.connection.
我收到 navigator.connection 的“未定义”。
Did I not include the network connection plugin correctly in my config.xml, or is something else amiss? Yes, I included the correct cordova.js file specifically for iOS. Yes, deviceready has been fired.
我是否没有在 config.xml 中正确包含网络连接插件,或者还有其他问题?是的,我包含了专门针对 iOS 的正确的cordova.js 文件。是的,deviceready 已被解雇。
Update: I am currently only running this on the iOS emulator.
更新:我目前只在 iOS 模拟器上运行它。
My config.xml:
我的 config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.app.test" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Hello Cordova</name>
<description>
Description
</description>
<author email="[email protected]" href="http://cordova.io">
Apache Cordova Team
</author>
<access origin="*" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
<plugins>
<plugin name="NetworkStatus" value="CDVConnection" />
</plugins>
</widget>
Thank you for your help!
感谢您的帮助!
回答by chadiusvt
Been doing my research on this one, and finally came up with the solution. Apparently PhoneGap (Adobe) recently updated their documentation, and filled in a lot of the holes I was running into for Phonegap 3.0.0
一直在研究这个,终于想出了解决方案。显然 PhoneGap (Adobe) 最近更新了他们的文档,并填补了我在 Phonegap 3.0.0 中遇到的很多漏洞
1) To do this using the command-line interface, you have to have git installed to be able to run those commands. Get git here.
1) 要使用命令行界面执行此操作,您必须安装 git 才能运行这些命令。在这里获取git。
2) They added to the Connectionplugin documentation to use the following command-line interface commands to add the plugin to the project:
2)他们在Connection插件文档中添加了使用以下命令行界面命令将插件添加到项目中:
$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git
$ cordova plugin rm org.apache.cordova.core.network-information
3) They updated the declaration in the config.xml file to the following (for iOS):
3) 他们将 config.xml 文件中的声明更新为以下内容(对于 iOS):
<feature name="NetworkStatus">
<param name="ios-package" value="CDVConnection" />
</feature>
回答by Mike
If you simply want to know if you are connected or not try using navigator.onLine in your js instead. Works for me on IOS 8 & Android 2.3 and doesn't require any plugins
如果您只是想知道您是否已连接,请尝试在您的 js 中使用 navigator.onLine。在 IOS 8 和 Android 2.3 上对我来说有效,不需要任何插件