Nhảy tới nội dung

getNetworkType

Lấy kiểu kết nối mạng hiện tại.

Parameters​

Object object​

PropertyTypeDefaultRequiredDescriptionMinimum Version
successfunctionCallback function khi gọi api thành công
failfunctionCallback function khi gọi api thất bại

Return Values​

Promise<Object data>​

PropertyTypeDescriptionMinimum Version
networkTypestringVới các giá trị:
  • 'none': Không có mạng
  • 'wifi': Mạng Wi-Fi
  • 'cellular': Mạng di động (2g/3g/4g)
  • 'unknown': Mạng không xác định (Android)

Sample Code​

import api from 'zmp-sdk';

api.getNetworkType({
success: (data) => {
// xử lý khi gọi api thành công
const { networkType } = data;
},
fail: (error) => {
// xử lý khi gọi api thất bại
console.log(error);
}
});

// hoặc
const test = async () => {
try {
const { networkType } = await api.getNetworkType({});
} catch (error) {
// xử lý khi gọi api thất bại
console.log(error);
}
};