Skip to content

Commit

Permalink
fix-conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
EhMidtJyde committed Jun 12, 2024
2 parents e7ba035 + 2c7972e commit 147f80e
Show file tree
Hide file tree
Showing 126 changed files with 5,394 additions and 540 deletions.
9 changes: 7 additions & 2 deletions .build/build.cake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#addin nuget:?package=Cake.Git&version=2.0.0
#addin nuget:?package=Cake.FileHelpers&version=5.0.0
#addin nuget:?package=Cake.Git&version=3.0.0
#addin nuget:?package=Cake.FileHelpers&version=6.1.3

using Path = System.IO.Path;
using System.Xml.Linq;
Expand Down Expand Up @@ -68,10 +68,15 @@ Task("BuildLibs")
Task("BuildClients")
.Does(() =>
{
// Xamarin
BuildProject("BLE.Client", "BLE.Client", Path.Combine("clients", "netstandard2.0"));
BuildProject("BLE.Client", "BLE.Client.Droid", Path.Combine("clients", "android"));
BuildProject("BLE.Client", "BLE.Client.iOS", Path.Combine("clients", "ios"));
BuildProject("BLE.Client", "BLE.Client.macOS", Path.Combine("clients", "macOS"));
BuildProject("BLE.Client", "BLE.Client.UWP", Path.Combine("clients", "uwp"));
// .NET 7/8
BuildProject("BLE.Client", "BLE.Client.WinConsole", Path.Combine("clients", "wincon"));
BuildProject("BLE.Client", "BLE.Client.Maui", Path.Combine("clients", "maui"));
});

Task("Clean").Does (() =>
Expand Down
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: janusw
67 changes: 50 additions & 17 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,54 @@ jobs:
winBuild:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: nuget/setup-nuget@v1
- uses: nuget/setup-nuget@v2
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- name: Install .NET MAUI
shell: pwsh
run: |
& dotnet nuget locals all --clear
& dotnet workload install maui --source https://aka.ms/dotnet6/nuget/index.json --source https://api.nuget.org/v3/index.json
& dotnet workload install android ios maccatalyst tvos macos maui wasm-tools maui-maccatalyst --source https://aka.ms/dotnet6/nuget/index.json --source https://api.nuget.org/v3/index.json
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1
uses: microsoft/setup-msbuild@v2
- name: Clean
uses: cake-build/cake-action@v1.4.1
uses: cake-build/cake-action@v2
with:
script-path: .build/build.cake
target: Clean
- name: Restore
uses: cake-build/cake-action@v1.4.1
uses: cake-build/cake-action@v2
with:
script-path: .build/build.cake
target: Restore
- name: Build Libs
uses: cake-build/cake-action@v1.4.1
uses: cake-build/cake-action@v2
with:
script-path: .build/build.cake
target: BuildLibs
- name: Build Clients
uses: cake-build/cake-action@v1.4.1
uses: cake-build/cake-action@v2
with:
script-path: .build/build.cake
target: BuildClients
- name: Builds Tests
uses: cake-build/cake-action@v1.4.1
uses: cake-build/cake-action@v2
with:
script-path: .build/build.cake
target: BuildTests
- name: Run Tests
uses: cake-build/cake-action@v1.4.1
uses: cake-build/cake-action@v2
with:
script-path: .build/build.cake
target: RunTests
Expand All @@ -64,22 +69,25 @@ jobs:
- name: Build MVVMCross.Plugins.BLE NuGet
run: msbuild .\Source\MvvmCross.Plugins.BLE\MvvmCross.Plugins.BLE.csproj /p:Configuration=Release /t:restore,build,pack /p:PackageOutputPath=./nuget /p:Version=$(git describe) /p:ContinuousIntegrationBuild=true /p:DeterministicSourcePaths=false
- name: Upload packages
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: nupkg
path: ./Source/*/nuget/*Plugin.BLE*.nupkg

macBuild:
runs-on: macos-latest
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: nuget/setup-nuget@v1
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Setup XCode
uses: maxim-lobanov/setup-xcode@v1
with:
dotnet-version: 7.0.x
xcode-version: '15'
- name: Install .NET MAUI
run: |
dotnet nuget locals all --clear
Expand All @@ -89,3 +97,28 @@ jobs:
run: dotnet build ./Source/Plugin.BLE/Plugin.BLE.csproj /p:Configuration=Release /t:restore,build,pack /p:Version=$(git describe) /p:ContinuousIntegrationBuild=true /p:DeterministicSourcePaths=false
- name: Build MVVMCross.Plugins.BLE NuGet
run: dotnet build ./Source/MvvmCross.Plugins.BLE/MvvmCross.Plugins.BLE.csproj /p:Configuration=Release /t:restore,build,pack /p:Version=$(git describe) /p:ContinuousIntegrationBuild=true /p:DeterministicSourcePaths=false
- name: Build MAUI sample
run: dotnet build ./Source/BLE.Client/BLE.Client.Maui/BLE.Client.Maui.csproj /p:Configuration=Release /t:restore,build /p:Version=$(git describe) /p:ContinuousIntegrationBuild=true /p:DeterministicSourcePaths=false

linuxBuild:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Install workloads
run: dotnet workload install android wasm-tools maui-android
- name: Install Android tools
run: |
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager \
--sdk_root=$ANDROID_SDK_ROOT "platform-tools"
- name: Build Plugin.BLE NuGet
run: dotnet build ./Source/Plugin.BLE/Plugin.BLE.csproj -p:Configuration=Release -t:restore,build,pack -p:Version=$(git describe) -p:ContinuousIntegrationBuild=true -p:DeterministicSourcePaths=false
- name: Build MVVMCross.Plugins.BLE NuGet
run: dotnet build ./Source/MvvmCross.Plugins.BLE/MvvmCross.Plugins.BLE.csproj -p:Configuration=Release -t:restore,build,pack -p:Version=$(git describe) -p:ContinuousIntegrationBuild=true -p:DeterministicSourcePaths=false
- name: Build MAUI sample
run: dotnet build ./Source/BLE.Client/BLE.Client.Maui/BLE.Client.Maui.csproj -p:Configuration=Release -t:restore,build -p:Version=$(git describe) -p:ContinuousIntegrationBuild=true -p:DeterministicSourcePaths=false
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
# Build results
.idea/
.idea.BLE/
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
Expand All @@ -29,6 +31,12 @@ bld/
FAKE*
!FAKE*.cs
.fake/
.idea/
*.dll
*.puibxml
*.pdb
*.DS_Store
.mono/

# Visual Studo 2015 cache/options directory
.vs/
Expand Down
67 changes: 35 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This project was forked in order to support some functionality required by the B
| Xamarin.iOS | 7.0 | |
| Xamarin.Mac | 10.9 (Mavericks) | >= 2.1.0 |
| Xamarin.UWP | 1709 - 10.0.16299 | >= 2.2.0 |
| MAUI (all 4 OS) | | >= 3.0.0 |
| MAUI (Android, iOS, Mac, WinUI) | | >= 3.0.0 |

## Nuget Packages

Expand Down Expand Up @@ -51,7 +51,9 @@ Install-Package MvvmCross.Plugin.BLE
Install-Package MvvmCross.Plugin.BLE -Pre
```

**Android**
## Permissions

### Android

Add these permissions to AndroidManifest.xml. For Marshmallow and above, please follow [Requesting Runtime Permissions in Android Marshmallow](https://devblogs.microsoft.com/xamarin/requesting-runtime-permissions-in-android-marshmallow/) and don't forget to prompt the user for the location permission.

Expand All @@ -67,45 +69,46 @@ Android 12 and above may require one or more of the following additional runtime
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />

```


Add this line to your manifest if you want to declare that your app is available to BLE-capable devices **only**:
```xml
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
````

**iOS**
### iOS

On iOS you must add the following keys to your `Info.plist`

<key>UIBackgroundModes</key>
<array>
<!--for connecting to devices (client)-->
<string>bluetooth-central</string>

<!--for server configurations if needed-->
<string>bluetooth-peripheral</string>
</array>

<!--Description of the Bluetooth request message (required on iOS 10, deprecated)-->
<key>NSBluetoothPeripheralUsageDescription</key>
<string>YOUR CUSTOM MESSAGE</string>

<!--Description of the Bluetooth request message (required on iOS 13)-->
<key>NSBluetoothAlwaysUsageDescription</key>
<string>YOUR CUSTOM MESSAGE</string>
```xml
<key>UIBackgroundModes</key>
<array>
<!--for connecting to devices (client)-->
<string>bluetooth-central</string>
<!--for server configurations if needed-->
<string>bluetooth-peripheral</string>
</array>

<!--Description of the Bluetooth request message (required on iOS 10, deprecated)-->
<key>NSBluetoothPeripheralUsageDescription</key>
<string>YOUR CUSTOM MESSAGE</string>

<!--Description of the Bluetooth request message (required on iOS 13)-->
<key>NSBluetoothAlwaysUsageDescription</key>
<string>YOUR CUSTOM MESSAGE</string>
````

**MacOS**
### MacOS

On MacOS (version 11 and above) you must add the following keys to your `Info.plist`:

<!--Description of the Bluetooth request message-->
<key>NSBluetoothAlwaysUsageDescription</key>
<string>YOUR CUSTOM MESSAGE</string>
```xml
<!--Description of the Bluetooth request message-->
<key>NSBluetoothAlwaysUsageDescription</key>
<string>YOUR CUSTOM MESSAGE</string>
````

**UWP**
### UWP

Add this line to the Package Manifest (.appxmanifest):

Expand All @@ -117,7 +120,7 @@ Add this line to the Package Manifest (.appxmanifest):

We provide a sample Xamarin.Forms app, that is a basic bluetooth LE scanner. With this app, it's possible to

- check the ble status
- check the BLE status
- discover devices
- connect/disconnect
- discover the services
Expand Down Expand Up @@ -329,14 +332,14 @@ The BLE API implementation (especially on **Android**) has the following limitat
}
```

- **Avoid caching of Characteristic or Service instances between connection sessions**. This includes saving a reference to them in your class between connection sessions etc. After a device has been disconnected all Service & Characteristic instances become **invalid**. Allways **use GetServiceAsync and GetCharacteristicAsync to get a valid instance**.
- **Avoid caching of Characteristic or Service instances between connection sessions**. This includes saving a reference to them in your class between connection sessions etc. After a device has been disconnected all Service & Characteristic instances become **invalid**. Always **use GetServiceAsync and GetCharacteristicAsync to get a valid instance**.

### General BLE iOS, Android

- Scanning: Avoid performing ble device operations like Connect, Read, Write etc while scanning for devices. Scanning is battery-intensive.
- try to stop scanning before performing device operations (connect/read/write/etc)
- try to stop scanning as soon as you find the desired device
- never scan on a loop, and set a time limit on your scan
- Scanning: Avoid performing BLE device operations like Connect, Read, Write etc while scanning for devices. Scanning is battery-intensive.
- Try to stop scanning before performing device operations (connect/read/write/etc).
- Try to stop scanning as soon as you find the desired device.
- Never scan on a loop, and set a time limit on your scan.

## How to build the nuget package

Expand Down
Loading

0 comments on commit 147f80e

Please sign in to comment.