Cordova 3 - iOs - navigator.connection Undefined

2019-08-11 02:26发布

Hi I'm trying to access connection on iOs device without any success...

I try to follow this post withot any result.

I run:

$ 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

and added:

<feature name="NetworkStatus">
    <param name="ios-package" value="CDVConnection" />
</feature>

in the config.xml file. I also try to wrap the feature lines in a <plugin></plugin> tag as I was not sure if it was needed, but nothing.

If I run from CLI: cordova plugin list

I obtain as expected: [ 'org.apache.cordova.network-information' ]

But I keep on getting undefined if I try to alert the connection type (I checked that I'm waiting the deviceReady event). Any suggestion on how to fix this?

Thanks in advance!

1条回答
对你真心纯属浪费
2楼-- · 2019-08-11 02:56

first of all, why would you run $ cordova plugin rm org.apache.cordova.core.network-information? what this does is removing your plugin, right after you installed it. somehow, of course, according to cordova plugin list the plugin is installed anyway, so let's move on.

make sure all plugin files are in the right spot. cordova 3 has the habit to not copy the native plugin files into the platform folder. you might have to manually copy the contents of your plugin's src/[platform] folder into the correct place in the platform folder. for ios it would be platforms/ios/[project name]/Plugins/[Plugin Name]. on android it's something like platforms/android/src/org/apache/cordova/[plugin name].

you don't have to do anything in config.xml, cordova does this automatically when you add a plugin via CLI. The only thing you might have to do manually is copying the native plugin files as I described above.

查看更多
登录 后发表回答