Skip to content

12 手机网络模块

Xiaomi-Yule edited this page Jan 20, 2021 · 1 revision

miot/system

手机网络相关接口

Export: public
Doc_name: 手机网络模块
Doc_index: 12
Doc_directory: system
Example

import {System} from "miot"
...
System.network.getGatewayIpAddress().then()
...

miot/system~INetwork

Kind: inner interface of miot/system


iNetwork.getGatewayIpAddress() ⇒ [ 'Promise' ].<object>

获取手机当前连接的路由器IP地址

Kind: instance method of INetwork
Returns: [ 'Promise' ].<object> - result: 成功时:{"code":0, "data":xxx},data.ipAddress:手机当前连接的路由器IP地址 失败时:{"code":-1, "message":"xxx" }
Since: 10045
Example

System.network.getGatewayIpAddress().then((res) => {
    if (res && res.data) {
      alert(`getGatewayIpAddress success,ipAddress:${ res.data.ipAddress }`);
    } else {
      alert(`getGatewayIpAddress fail,${ JSON.stringify(res) }`);
    }
  }).catch((error) => {
    alert(`getGatewayIpAddress fail,${ JSON.stringify(error) }`);
  });

iNetwork.getWifiBroadcastAddress() ⇒ [ 'Promise' ].<object>

获取当前wifi的广播地址

Kind: instance method of INetwork
Returns: [ 'Promise' ].<object> - result: 成功时:{"code":0, "data":{"address":xxx.xxx.xxx}} 失败时:{"code":-1, "message":"xxx" }
Since: 10047
Example

System.network.getGatewayIpAddress().then( res =>{
 alert(JSON.stringify(res));
}).catch(err =>{
 alert(JSON.stringify(err));
})

Clone this wiki locally