"react-native-lanscan "抛出一个异常! undefined不是一个对象(评价'this.RNLAN_Scan.scan')?

问题描述 投票:1回答:1

为了在我的 react-native 移动应用中执行 icmp 广播,我使用了 react-native-lanscan 包。

import { LANScan } from 'react-native-lanscan';
.
.
var lanscan = new LANScan();
.
.
pingBroadcaster = () => {
    console.log("Lanscan started!");         // to get log
    lanscan.scan(48500, 48503, 500, true);
    lanscan.on('host_found', (host, currentAvailableHosts) => {
        console.log(typeof(host));           // to get log
    })
    console.log("Lanscan ended!");           // to get log
}

当在arrow函数中调用scan方法时,它会导致异常。"undefined is not an object(evalating 'this.RNLAN_Scan.scan')"。

增加了一些线条到 扫描 的方法 兰扫描 包,以找出哪一行导致错误。

    function scan(min_port,max_port){
        console.log("   Function scan variable declaration");  // to get log
        var broadcast_timeout=arguments.length>2&&arguments[2]!==undefined?arguments[2]:500;
        var fallback=arguments.length>3&&arguments[3]!==undefined?arguments[3]:true;
        var ping_ms=arguments.length>4&&arguments[4]!==undefined?arguments[4]:50;
        var port_ms=arguments.length>5&&arguments[5]!==undefined?arguments[5]:500;
        console.log("   Function call: " + RNLAN_Scan);        // to get log
        this.RNLAN_Scan.scan(min_port,max_port,broadcast_timeout,fallback,ping_ms,port_ms);
        console.log("   Function scan Ends!");                 // to get log        
    }return scan;}()},

我已经收到了这些日志。

Lanscan started!
   Function scan variable declaration
   Function call: null
::ffff:192.168.43.1 - - [26/Feb/2020:14:23:16 +0000] "POST /symbolicate HTTP/1.1" 200 - "-" "okhttp/3.12.1"
Lanscan started!
   Function scan variable declaration
   Function call: null
::ffff:192.168.43.1 - - [26/Feb/2020:14:23:21 +0000] "POST /symbolicate HTTP/1.1" 200 - "-" "okhttp/3.12.1"
Lanscan started!
   Function scan variable declaration
   Function call: null
::ffff:192.168.43.1 - - [26/Feb/2020:14:23:26 +0000] "POST /symbolicate HTTP/1.1" 200 - "-" "okhttp/3.12.1"
Lanscan started!

好像是... RNLAN_Scan 返回 无效 我不确定,但也许是这一行出了问题......在我的react-native移动应用中执行icmp广播,我使用react-native-lanscan包。

var RNLAN_Scan=_reactNative.NativeModules.RNLANScan;
javascript react-native node-modules ping icmp
1个回答
热门问题
推荐问题
最新问题