nativescript-lan-scan
NativeScript 的 iOS MMLanScan CocoaPod 封装 [测试版]
npm i --save nativescript-lan-scan

NativeScript LanScan [测试版]

(仅限 iOS)

入门指南

此插件是对 iOS MMLanScan 库的封装: https://github.com/mavris/MMLanScan

要在 NativeScript 应用中使用此插件

  1. 运行: tns plugin add nativescript-lan-scan

它做什么?

此插件会扫描本地网络,并返回一个包含所有检测到的 IP 和 MAC 地址的数组。有关详细信息,请参阅原始的 MMLanScan

如何使用它?

将插件添加到您的 NativeScript 应用

tns plugin add nativescript-lan-scan

将插件包含在您的应用中。如果使用 TypeScript,还需要包含一些事件类,以确保 TypeScript 能够正常工作。

import { LanScan, FoundDeviceEventData, DeviceInfo, PingProgressEvent, PingProgress }

var lanScan = new LanScan();

// Wire up callback events from the Lan Scanner

// Fires whenever a devices is discovered
this._lanScan.on(LanScan.foundNewDeviceEvent, (args: FoundDeviceEventData) => {
// Device info is found on the args.deviceInfo object...
// args.deviceInfo.ipAddress
// args.deviceInfo.macAddress
});

// Fires everytime an address on the subnet is pinged
this._lanScan.on(LanScan.progressPingedEvent, (args: PingProgressEventData) => {
// args.pingProgress.overallHosts - total number hosts that the scanner will ping through
// args.pingProgress.pingedHosts - current number of hosts that have been pinged
});

this._lanScan.on(LanScan.scanningFinishedEvent, (args) => {
// Status: enum...
// 0: Finished
// 1: Stopped
});

// Start the Lan Scanner
lanScan.start();


// If, in the middle of the operation you want to stop the scan
lanScan.stop();

// Get the SSID
// Note that this doesn't work in the simulator,
// it will say "No Wifi Available"
let ssid = lanScan.fetchSSIDInfo();