1 Star 0 Fork 0

levi_plugin/flutter_network_info_plus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
zero- zero 111 17bdd4d 3年前
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

network_info_plus

Flutter Community: network_info_plus

pub package

build

This plugin allows Flutter apps to discover network info and configure themselves accordingly.

Platform Support

Android iOS MacOS Web Linux Windows
✔️ ✔️ ✔️ ✔️ ✔️

The functionality is not supported on Web.

Usage

You can get wi-fi related information using:

import 'package:network_info_plus/network_info_plus.dart';

final info = NetworkInfo();

var wifiName = await info.getWifiName(); // FooNetwork
var wifiBSSID = await info.getWifiBSSID(); // 11:22:33:44:55:66
var wifiIP = await info.getWifiIP(); // 192.168.1.43
var wifiIPv6 = await info.getWifiIPv6(); // 2001:0db8:85a3:0000:0000:8a2e:0370:7334
var wifiSubmask = await info.getWifiSubmask(); // 255.255.255.0
var wifiBroadcast = await info.getWifiBroadcast(); // 192.168.1.255
var wifiGateway = await info.getWifiGatewayIP(); // 192.168.1.1

Android

To successfully get WiFi Name or Wi-Fi BSSID starting with Android 1O, ensure all of the following conditions are met:

  • If your app is targeting Android 10 (API level 29) SDK or higher, your app needs to have the ACCESS_FINE_LOCATION permission.

  • If your app is targeting SDK lower than Android 10 (API level 29), your app needs to have the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.

  • Location services are enabled on the device (under Settings > Location).

This package does not provide the ACCESS_FINE_LOCATION nor the ACCESS_COARSE_LOCATION permission by default

iOS 12

To use .getWifiBSSID() and .getWifiName() on iOS >= 12, the Access WiFi information capability in XCode must be enabled. Otherwise, both methods will return null.

iOS 13

The methods .getWifiBSSID() and .getWifiName() utilize the CNCopyCurrentNetworkInfo function on iOS.

As of iOS 13, Apple announced that these APIs will no longer return valid information. An app linked against iOS 12 or earlier receives pseudo-values such as:

  • SSID: "Wi-Fi" or "WLAN" ("WLAN" will be returned for the China SKU).

  • BSSID: "00:00:00:00:00:00"

An app linked against iOS 13 or later receives null.

The CNCopyCurrentNetworkInfo will work for Apps that:

  • The app uses Core Location, and has the user’s authorization to use location information.

  • The app uses the NEHotspotConfiguration API to configure the current Wi-Fi network.

  • The app has active VPN configurations installed.

If your app falls into the last two categories, it will work as it is. If your app doesn't fall into the last two categories, and you still need to access the wifi information, you should request user's authorization to use location information.

There is a helper method provided in this plugin to request the location authorization: requestLocationServiceAuthorization. To request location authorization, make sure to add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:

  • NSLocationAlwaysAndWhenInUseUsageDescription - describe why the app needs access to the user’s location information all the time (foreground and background). This is called Privacy - Location Always and When In Use Usage Description in the visual editor.
  • NSLocationWhenInUseUsageDescription - describe why the app needs access to the user’s location information when the app is running in the foreground. This is called Privacy - Location When In Use Usage Description in the visual editor.

Check out our documentation website to learn more. Plus plugins documentation

Important: As of January 2021, the Flutter team is no longer accepting non-critical PRs for the original set of plugins in flutter/plugins, and instead they should be submitted in this project. You can read more about this announcement here. as well as in the Flutter 2 announcement blog post.

// Copyright 2017 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

network_info_plus插件删除定位权限 展开 收起
README
BSD-3-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/plugin_levi/flutter_network_info_plus.git
git@gitee.com:plugin_levi/flutter_network_info_plus.git
plugin_levi
flutter_network_info_plus
flutter_network_info_plus
master

搜索帮助