All Products
Search
Document Center

Mobile Platform as a Service:Network status

Last Updated:Feb 05, 2021

my.getNetworkType

This API is supported in mPaaS 10.1.32 and later versions.

This API is used to get the current network status.

Input parameter

Name Type Required Description
success Function No Callback function for successful call
fail Function No Callback function for failed call
complete Function No Callback function for ended call (executed regardless of whether the call is successful or failed)

success return value

Name Type Description
networkAvailable Boolean Whether the network is available
networkType String The possible network type values are UNKNOWN/NOTREACHABLE/WIFI/3G/2G/4G/WWAN

Code sample

  1. Page({
  2. data: {
  3. hasNetworkType: false
  4. },
  5. getNetworkType() {
  6. my.getNetworkType({
  7. success: (res) => {
  8. this.setData({
  9. hasNetworkType: true,
  10. networkType: res.networkType
  11. })
  12. }
  13. })
  14. },
  15. clear() {
  16. this.setData({
  17. hasNetworkType: false,
  18. networkType: ''
  19. })
  20. },
  21. });

my.onNetworkStatusChange(CALLBACK)

This API is supported in mPaaS 10.1.32 and later versions.

Start monitoring changes in network status.

Return value

Name Type Description
isConnected Boolean Whether the network is available
networkType String The possible network type values are UNKNOWN/NOTREACHABLE/WIFI/3G/2G/4G/WWAN

Code sample

  1. my.onNetworkStatusChange(function(res){
  2. console.log(JSON.stringify(res))
  3. })

my.offNetworkStatusChange

This API is supported in mPaaS 10.1.32 and later versions.

Cancel monitoring changes in network status.

Code sample

  1. my.offNetworkStatusChange()

Whether to pass the callback value

  • If the callback value is not passed, all event callbacks will be removed. The code sample is as follows:
    1. my.offNetworkStatusChange();
  • If the callback value is passed, only remove the corresponding callback event. The code sample is as follows:
    1. my.offNetworkStatusChange(this.callback);