GithubHelp home page GithubHelp logo

huafangyun / triaxis.bluetoothle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from triaxis-oss/triaxis.bluetoothle

0.0 1.0 0.0 267 KB

Simple cross-platform BluetoothLE library for Xamarin.Forms

License: MIT License

C# 100.00%

triaxis.bluetoothle's Introduction

triaxis.BluetoothLE

Simple cross-platform Bluetooth LE library

Basic Usage

  1. reference the triaxis.BluetoothLE nuget from your MAUI or Xamarin application

  2. make the IBluetoothLE available to the application

    MAUI: call the IServiceCollection.AddBluetoothLE () extension method during application startup:

        var builder = MauiApp.CreateBuilder();
        // register platform-specific IBluetoothLE implementation in the container
        builder.Services.AddBluetoothLE();

    Xamarin: you can use the the DependencyService to register the triaxis.BluetoothLE.Platform class as an IBluetoothLE implementation

  3. observe the IBluetoothLE.WhenAdapterChanges() observable - it will always return at least the current adapter state

  4. when the returned IAdapter.State == AdapterState.On, you can initiate a scan for advertisements using IAdapter.Scan() which returns another observable of IAdvertisements

  5. you can use the IAdvertisements to either just monitor nearby devices through the data exposed by the interface, or use the IAdvertisement.Peripheral to connect to the device

Platform-specific requirements

Android

For Android applications to be able to access Bluetooth LE, at least one of the location permissions must be requested, and the application must also ask the system for location access.

A simple trick to handle the location request is to use the Xamarin/MAUI essentials to retrieve the current location in the MainActivity

    protected override void OnPostResume()
    {
        base.OnPostResume();

        _ = Geolocation.GetLastKnownLocationAsync();
    }

iOS, MacCatalyst

A reason string has to be provided in the corresponding Info.plist file, e.g.:

	<key>NSBluetoothAlwaysUsageDescription</key>
	<string>This app scans for Bluetooth devices</string>

Example

See the DeviceBrowser example for a very simple MAUI application that just scans for advertising devices

License

This package is licensed under the MIT License

Copyright © 2022 triaxis s.r.o.

triaxis.bluetoothle's People

Contributors

ssimek avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.