Skip to content

Commit

Permalink
Merge pull request exendahal#21 from exendahal/doc/update_readme
Browse files Browse the repository at this point in the history
Update readme document
  • Loading branch information
exendahal authored Dec 7, 2024
2 parents 6282d35 + 2985c14 commit fb6ab00
Showing 1 changed file with 89 additions and 91 deletions.
180 changes: 89 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
# Wifi Manager for .NET MAUI
# Wi-Fi Manager for .NET MAUI

Welcome to the documentation for the MAUI Wi-Fi Manager library, a comprehensive solution designed specifically for MAUI. This library empowers developers to effortlessly manage Wi-Fi networks within their cross-platform applications. With its intuitive APIs, you can seamlessly integrate Wi-Fi functionality, allowing users to connect to, add, and retrieve information about Wi-Fi networks with ease.
The Wi-Fi Manager for .NET MAUI is a simple and powerful library that helps you manage Wi-Fi networks in your cross-platform apps. With this library, you can easily connect to Wi-Fi networks, retrieve network information, and provide quick access to Wi-Fi and wireless settings.

[![WifiManager.Maui](https://img.shields.io/nuget/v/WifiManager.Maui)](https://www.nuget.org/packages/WifiManager.Maui/)

---

## Platform Support
## Supported Platforms

| S. No. | Platform | Support | Remarks |
| ------ | ------------ | --------- | ----------- |
| 1. | Android | ☑ | |
| 2. | iOS | ☑ | |
| 3. | Windows | ☑ | |
| 4. | Mac | ☒ | Coming Soon |
| 5. | Tizen | ☒ | Coming Soon |
| Platform | Supported | Notes |
|-----------|-----------|----------------------------------|
| Android | | |
| iOS | | |
| Windows | | |
| Mac | | |
| Tizen | | |

## Features
---

- Connect Wi-Fi with SSID and Password: Enable users to connect to Wi-Fi networks by providing the SSID and password.
- Add a New Wi-Fi Network: Seamlessly add new Wi-Fi networks to the device.
- Get Current Network Info: Retrieve information about the currently connected Wi-Fi network.
- Disconnect Wi-Fi: Allow users to disconnect from a Wi-Fi network.
- Open Wi-Fi Setting: Provide a quick way for users to access their device's Wi-Fi settings.
## Key Features

## Getting started
- **Connect to Wi-Fi**: Connect to Wi-Fi networks using SSID and password.
- **Get Network Info**: View details about the currently connected network.
- **Disconnect Wi-Fi**: Disconnect from a specific Wi-Fi network.
- **Open Wi-Fi Settings**: Provide quick access to device Wi-Fi settings.
- **Open Wireless Settings**: Provide quick access to device wireless settings.

---

## How to Get Started

### Initialization

Before using the MAUI Wi-Fi Manager plugin in your application, it's essential to initialize it. Here's how to do it on different platforms:
Before using the library, make sure to initialize it properly:

#### Android
#### For Android

To use the MAUI Wi-Fi Manager on Android, you must initialize the plugin. Add the following code to your Android application:
Add the following to your Android app initialization:

```csharp
WifiNetworkService.Init(this);
WifiNetworkService.Init(this);
```

Android Permissions
Also, include these permissions in your `AndroidManifest.xml` file:

```xml
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Expand All @@ -48,120 +53,113 @@ Android Permissions
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
```

Make sure you request location before scanning Wi-Fi
Make sure to request location permissions before scanning for Wi-Fi.

#### iOS
#### For iOS

Add wifi-info and HotspotConfiguration in Entitlements.plist
Add the following to your `Entitlements.plist`:

```xml
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.networking.wifi-info</key>
<true/>
<key>com.apple.developer.networking.HotspotConfiguration</key>
<true/>
</dict>
</plist>
<key>com.apple.developer.networking.wifi-info</key>
<true/>
<key>com.apple.developer.networking.HotspotConfiguration</key>
<true/>
```

Request location permission on info.plist
In `Info.plist`, request location permissions:

```xml
<key>NSLocationWhenInUseUsageDescription</key>
<string>App want to access location to get ssid</string>
<string>The app needs location access to detect Wi-Fi networks.</string>
```

Example
---

```csharp
PermissionStatus status = await Permissions.RequestAsync<Permissions.LocationWhenInUse>();
if (status == PermissionStatus.Granted)
{
var response = await CrossWifiManager.Current.ScanWifiNetworks();
}
else
await DisplayAlert("No location permission", "Please provide location permission", "OK");
```
## Examples

#### Connect to Wi-Fi
### Connect to Wi-Fi

To connect to a Wi-Fi network programmatically, use the ConnectWifi method. This method takes the SSID and password as parameters. Here's an example:
To connect to a Wi-Fi network:

```csharp
var response = await CrossWifiManager.Current.ConnectWifi(ssid, password);
var response = await CrossWifiManager.Current.ConnectWifi("your-SSID", "your-password");
```

The NetworkData class is defined as follows:
---

### Scan for Available Networks

To get a list of available Wi-Fi networks (Android & Windows only):

```csharp
public class NetworkData
{
public int StausId { get; set; }
public string Ssid { get; set; }
public int IpAddress { get; set; }
public string GatewayAddress { get; set; }
public object NativeObject { get; set; }
public object Bssid { get; set; }
public object SignalStrength { get; set; }
}
var response = await CrossWifiManager.Current.ScanWifiNetworks();
```

#### Scan available Wi-Fi (Not available on iOS)
---

You can access available Wi-Fi networks using the ScanWifiNetworks method (Available on Android & Windows):
### Get Current Network Info

To retrieve details of the currently connected Wi-Fi network:

```csharp
var response = await CrossWifiManager.Current.ScanWifiNetworks();
var response = await CrossWifiManager.Current.GetNetworkInfo();
```

#### Get Wi-Fi info
---

### Disconnect Wi-Fi

You can retrieve information about the currently connected Wi-Fi network using the GetNetworkInfo method:
To disconnect from a Wi-Fi network:

```csharp
var response = await CrossWifiManager.Current.GetNetworkInfo();
await CrossWifiManager.Current.DisconnectWifi("your-SSID");
```

#### Disconnect Wi-Fi
---

To disconnect from a Wi-Fi network, simply call the DisconnectWifi method with the SSID as a parameter:
### Open Wireless Settings

To open the device's wireless settings:

```csharp
CrossWifiManager.Current.DisconnectWifi(ssid);
await CrossWifiManager.Current.OpenWirelessSetting();
```

#### Open Wi-Fi Setting
**Note**: On iOS, this opens the app's settings instead of wireless settings.

---

If you want to provide users with a convenient way to access their device's Wi-Fi settings, use the OpenWifiSetting method:
### Open Wi-Fi Settings

To provide quick access to Wi-Fi settings:

```csharp
var response = await CrossWifiManager.Current.OpenWifiSetting();
await CrossWifiManager.Current.OpenWifiSetting();
```

I value your feedback! If you encounter any issues, have suggestions for improvement, or wish to report bugs, please open an issue on GitHub or GitLab repository
**Note**: On iOS, this opens the app's settings instead of Wi-Fi settings.

## License
---

MIT License
## Feature Support by Platform

Copyright (c) 2023 Santosh Dahal
| Feature | Android | iOS | Windows | Notes |
|----------------------------------|---------|-----------|---------|-----------------------------------------|
| Connect to Wi-Fi |||| Supported on all platforms. |
| Get Current Network Info |||| Supported on all platforms. |
| Disconnect Wi-Fi |||| Supported on all platforms. |
| Scan for Available Wi-Fi Networks|||| Not supported on iOS. |
| Open Wireless Settings ||* || *Opens app settings on iOS. |
| Open Wi-Fi Settings ||* || *Opens app settings on iOS. |

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
---

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
## Feedback & Issues

If you encounter any issues or have suggestions, please open an issue on the project's GitHub or GitLab repository.

---

## License

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

0 comments on commit fb6ab00

Please sign in to comment.