gxvigo
gxvigo

Reputation: 837

navigator.connection not available in Worklight 6

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

Upvotes: 0

Views: 495

Answers (3)

nspeete
nspeete

Reputation: 659

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.

Upvotes: 2

christianmenkens
christianmenkens

Reputation: 790

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

Upvotes: 0

Srik
Srik

Reputation: 7957

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

Upvotes: 0

Related Questions