搜尋套件、儲存庫與 APP 分類

套件詳情v0.3.1

beacon_broadcast

一個將您的裝置轉換為信標的 Flutter 外掛程式。該外掛程式在 Android 上使用 AltBeacon 庫,在 iOS 上使用 CoreLocation。

AndroidiOS
近 30 天下載
184
喜歡數
43
Pub 分數
140

安裝套件

flutter pub add beacon_broadcast

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

beacon_broadcast 套件讓 Flutter 應用程式能夠使用 Android 上的 AltBeacon 庫與 iOS 上的 CoreLocation 將裝置轉換為藍牙信標。它允許開發者廣播自訂信標訊號,適用於基於距離的互動,例如室內導航、位置觸發通知或資產追蹤。此外,該套件專為跨平台相容性設計,並能順暢整合至現有的信標生態系統。支援前景與背景信標傳輸,確保設備在各種狀態下皆能持續廣播訊號。

適用情境

  • 室內導航系統
  • 近場行銷
  • 倉庫中的資產追蹤
  • 基於位置的應用程式觸發
  • 智慧家庭自動化

主要特色

  • 跨平台支援(Android 與 iOS)
  • 使用 AltBeacon 和 CoreLocation 框架
  • 可自訂信標 UUID、主要和次要值
  • 背景信標廣播
  • 用於啟動/停止廣播的簡單API

適合對象

  • 開發接近性應用的開發者
  • 需要室內定位的應用
  • 零售或企業位置服務
  • 物聯網和智慧環境專案

使用建議

  • 兩個平台都需要藍牙權限
  • 連續廣播期間電池使用量可能會增加
  • iOS 後台模式需要正確設定
  • 信標檢測取決於附近設備的掃描能力

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Beacon Broadcast plugin for Flutter

Awesome Flutter Pub

A Flutter plugin for turning your device into a beacon.

Usage

To use this plugin, add beacon_broadcast as a dependency in your pubspec.yaml file and import:

import 'package:beacon_broadcast/beacon_broadcast.dart';

Now you can create BeaconBroadcast object and start using it:

Important note: For Android app, user needs to turn on Bluetooth on the device first.

BeaconBroadcast beaconBroadcast = BeaconBroadcast();

In the simplest case, to start advertising just set your UUID, major and minor id and call start():

beaconBroadcast
    .setUUID('39ED98FF-2900-441A-802F-9C398FC199D2')
    .setMajorId(1)
    .setMinorId(100)
    .start();

You can also customize your beacon before starting:

beaconBroadcast
    .setUUID('39ED98FF-2900-441A-802F-9C398FC199D2')
    .setMajorId(1)
    .setMinorId(100)
    .setTransmissionPower(-59) //optional
    .setAdvertiseMode(AdvertiseMode.lowPower) //Android-only, optional
    .setIdentifier('com.example.myDeviceRegion') //iOS-only, optional
    .setLayout('s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v') //Android-only, optional
    .setManufacturerId(0x001D) //Android-only, optional
    .start();

You can check what's current state of your beacon:

bool isAdvertising = await beaconBroadcast.isAdvertising()

You can also listen for changes in beacon advertising state:

beaconBroadcast.getAdvertisingStateChange().listen((isAdvertising) {
    // Now you know if beacon is advertising
});

Before advertising, you may want to check if your device supports transmitting as a beacon. You may do it using checkTransmissionSupported() method.

BeaconStatus transmissionSupportStatus = await beaconBroadcast.checkTransmissionSupported();
switch (transmissionSupportStatus) {
  case BeaconStatus.SUPPORTED:
    // You're good to go, you can advertise as a beacon
    break;
  case BeaconStatus.NOT_SUPPORTED_MIN_SDK:
    // Your Android system version is too low (min. is 21)
    break;
  case BeaconStatus.NOT_SUPPORTED_BLE:
    // Your device doesn't support BLE
    break;
  case BeaconStatus.NOT_SUPPORTED_CANNOT_GET_ADVERTISER:
    // Either your chipset or driver is incompatible
    break;
}

If you want to stop advertising, just call stop():

beaconBroadcast.stop();
Examples

Simple usage example can be found in the example folder.

Changing beacon layouts

By default beacons layout is set according to the manufacturer (see section Beacon manufacturers). You can change that layout to imitate transmitting as a different kind of beacon.

Note: For iOS layout is set to iBeacon and can't be changed.

To broadcast as AltBeacon:

beaconBroadcast
    .setUUID('39ED98FF-2900-441A-802F-9C398FC199D2')
    .setMajorId(1)
    .setMinorId(100)
    .start();

To broadcast as iBeacon:

beaconBroadcast
    .setUUID('39ED98FF-2900-441A-802F-9C398FC199D2')
    .setMajorId(1)
    .setMinorId(100)
    .setLayout('m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24')
    .setManufacturerId(0x004c)
    .start();
Adding extra data

If you have your beacon layout set accordingly, you're allowed to transmit some extra data. Depending on the layout it's usually up to 2 bytes.

For AltBeacon it's 1 byte of additional data (source). For iBeacon (iOS) there's no option to send extra data, as the iBeacon layout doesn't support it.

To add extra data using AltBeacon layout:

beaconBroadcast
    .setUUID('39ED98FF-2900-441A-802F-9C398FC199D2')
    .setMajorId(1)
    .setMinorId(100)
    .setExtraData([123])
    .start();
Beacon manufacturers
Android

Android beacon will advertise as the AltBeacon manufactured by RadiusNetwork. You can change it with setLayout() and setManufacturerId() methods.

iOS

For iOS, beacon will advertise as an iBeacon (by Apple), it can't be changed.

Transmitting in the background
Android

Due to background execution limits introduced in Android 8 beacons transmission in the background is limited. Based on the AltBeacon documentation it's around 10 minutes, after that time transmission will stop. Current version of plugin doesn't support Foreground Services to exceed this limitation.

iOS

For iOS, application doesn't work in the background. According to the CoreLocation documentation:

Important

After advertising your app as a beacon, your app must continue running in the foreground to broadcast the needed Bluetooth signals. If the user quits the app, the system stops advertising the device as a peripheral over Bluetooth.In addition, since iOS 13, a privacy usage description is required to use Bluetooth. Otherwise, the app will experience a runtime crash. To remedy this, add the following lines to your Info.plist

<key>NSBluetoothAlwaysUsageDescription</key>
<string>(Reason bluetooth is used)</string>

For deployment targets earlier than iOS 13, add these additional lines to your Info.plist

<key>NSBluetoothPeripheralUsageDescription</key>
<string>(Reason bluetooth is used)</string>
About

This plugin uses Android Beacon Library for Android and CoreLocation for iOS.

Todo

There are still few things left to implement:

  • [X] Adding option for checking for Android device support programmatically
  • [X] Adding option to set layout and manufacturer for Android implementation
  • [ ] Handle turning on BLE before transmitting
  • [ ] Add Foreground Service to exceed background limitations on Android 8+

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。