0

I need to check network connectivity from my app. I found that cordova provides this feature: http://cordova.apache.org/docs/en/2.5.0/cordova_connection_connection.md.html#Connection

but when I test my app in preview in Chrome, when the code reach "return navigator.connection.type.toString();" from my app I see following error:

"cannot read property 'type' of undefined"

If in Chrome's console I write navigator Chrome shows me then the possible options, and connection is not one of those. The same app tested in Android emulator, works fine

I use navigator.geolocation to get location and display a map and it works just fine.

Thanks, Giovanni

gxvigo
  • 787
  • 4
  • 10
  • 20

3 Answers3

2

Both navigator.network.connection.type and navigator.connection.type are supported in the latest Worklight 6.1's Mobile Browser Simulator (Worklight 6.1 uses Cordova 3.1). Up to Cordova 2.3.0, the Connection object was accessed from navigator.network.connection. After Cordova 2.3.0 it was changed to navigator.connection. Navigator.network.connection is still available in Cordova 3.1, but is deprecated and will be eventually removed from Cordova.

nspeete
  • 659
  • 3
  • 10
0

You can use the WL.Device.getNetworkInfo to get network information from a Worklight app. Documentation is available at http://pic.dhe.ibm.com/infocenter/wrklight/v6r0m0/index.jsp?topic=%2Fcom.ibm.worklight.help.doc%2Fapiref%2Fr_mobile_network_details.html

Srik
  • 7,907
  • 2
  • 20
  • 29
  • please note that due to the problem with the simulator mentioned above, this call only works on the device and not in the Preview Simulator that you can start from WL Studio. – christianmenkens Sep 03 '13 at 19:12
0

Please see that there is a Problem with the Simulator - I assume you are using that - because Preview in Worklight Studio starts the Mobile Simulator.

IBM Worklight 5.0.6.1 - Mobile Browser Simulator - WL.Device.getNetworkInfo for navigator.network.connection.type vs. navigator.connection.type

Community
  • 1
  • 1
christianmenkens
  • 790
  • 4
  • 22