react-native-network-info'null 不是对象'
2020-10-25
1285
无论我使用 react-native-network-info 的哪个函数,我总是会收到警告([Unhandled promise rejection: TypeError: null is not an object (evaluating 'RNNetworkInfo.getGatewayIPAddress')])并且该函数不返回任何内容。请参阅代码示例。 我也已经尝试完全按照文档中所述进行操作( https://www.npmjs.com/package/react-native-network-info ):
// Get Default Gateway IP
NetworkInfo.getGatewayIPAddress().then(defaultGateway => {
console.log(defaultGateway);
});
import { NetworkInfo } from "react-native-network-info";
_updateStates = () => {
...
...
NetworkInfo.getGatewayIPAddress((gateway) => {
console.log(gateway);
});
};
2个回答
您没有在代码中添加“then”。尝试一下
_updateStates = () => {
...
...
NetworkInfo.getGatewayIPAddress().then(gateway => {
console.log(gateway);
});
};
Mehran Khan
2020-10-25