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

套件詳情v2.0.8

beacons_plugin

此外掛可讓您在 Flutter 應用中更輕鬆地掃描附近的 iBeacon 並進行範圍測量。掃描到的 Beacon 將提供接近度值。

AndroidiOS
近 30 天下載
261
喜歡數
64
Pub 分數
130

安裝套件

flutter pub add beacons_plugin

套件介紹

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

beacons_plugin 插件簡化了在 Flutter 應用中對 iBeacon 的掃描和測距,適用於 Android 和 iOS。它使開發者能夠檢測附近的 iBeacon 並接收即時的接近度更新,例如立即、靠近或遠離。該插件與原生藍牙功能無縫整合,提供簡單易用的 API 來監控信標訊號,無需複雜設定。非常適合用於基於位置的服務、室內導航和情境感知應用。

適用情境

  • 室內導航系統
  • 基於距離的通知
  • 零售客戶參與
  • 資產追蹤
  • 上下文感知的移動體驗

主要特色

  • 即時信標掃描
  • 接近檢測(立即、靠近、遠離)
  • 跨平台支援(Android 與 iOS)
  • 與 Flutter 的簡單整合
  • 背景監控功能

適合對象

  • 開發位置感知應用程式的開發者
  • 零售和酒店應用
  • 智慧辦公和校園解決方案
  • 基於事件的通知系統
  • 室內定位專案

使用建議

  • 兩個平台都需要藍牙權限
  • 限於iBeacon協議
  • 背景掃描可能會影響電池壽命
  • iOS 需要背景模式設定
  • 準確性取決於環境因素

原始 README

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

beacons_plugin

pub package

This plugin is developed to scan nearby iBeacons on both Android iOS. This library makes it easier to scan & range nearby BLE beacons and read their proximity values.

Android

For Android change min SDK version:

defaultConfig {
  ...
  minSdkVersion 19
  ...
}

Change your Android Project's MainActivity class to following:

import com.umair.beacons_plugin.BeaconsPlugin
import io.flutter.embedding.android.FlutterActivity

class MainActivity : FlutterActivity(){

    override fun onPause() {
        super.onPause()

        //Start Background service to scan BLE devices
        BeaconsPlugin.startBackgroundService(this)
    }

    override fun onResume() {
        super.onResume()

        //Stop Background service, app is in foreground
        BeaconsPlugin.stopBackgroundService(this)
    }
}

That's it for Android.

iOS

In your AppDelegate.swift file change it to like this:

    
    import UIKit
    import Flutter
    import CoreLocation
    
    @UIApplicationMain
    @objc class AppDelegate: FlutterAppDelegate {
    
        let locationManager = CLLocationManager()
    
        override func application(
            _ application: UIApplication,
            didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
        ) -> Bool {
    
            locationManager.requestAlwaysAuthorization()
            GeneratedPluginRegistrant.register(with: self)
    
            return super.application(application, didFinishLaunchingWithOptions: launchOptions)
        }
    }

In your Info.plist file add following lines:

    <dict>
      <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    	<string>App needs location permissions to scan nearby beacons.</string>
    	<key>NSLocationWhenInUseUsageDescription</key>
    	<string>App needs location permissions to scan nearby beacons.</string>
    	<key>NSLocationAlwaysUsageDescription</key>
    	<string>App needs location permissions to scan nearby beacons.</string>
    </dict>

Install

In your pubspec.yaml

dependencies:
  beacons_plugin: [LATEST_VERSION]
import 'dart:async';
import 'dart:io' show Platform;
import 'package:flutter/services.dart';
import 'package:beacons_plugin/beacons_plugin.dart';

Ranging Beacons & Setting Up

    // if you need to monitor also major and minor use the original version and not this fork
    BeaconsPlugin.addRegion("myBeacon", "01022022-f88f-0000-00ae-9605fd9bb620")
        .then((result) {
          print(result);
        });
    
    //Send 'true' to run in background [OPTIONAL]
    await BeaconsPlugin.runInBackground(true);
    
    //IMPORTANT: Start monitoring once scanner is setup & ready (only for Android)
    if (Platform.isAndroid) {
      BeaconsPlugin.channel.setMethodCallHandler((call) async {
        if (call.method == 'scannerReady') {
          await BeaconsPlugin.startMonitoring();
        }
      });
    } else if (Platform.isIOS) {
      await BeaconsPlugin.startMonitoring();
    }
    

Listen To Beacon Scan Results as Stream

    
    final StreamController<String> beaconEventsController = StreamController<String>.broadcast();
    BeaconsPlugin.listenToBeacons(beaconEventsController);
    
    beaconEventsController.stream.listen(
        (data) {
          if (data.isNotEmpty) {
            setState(() {
              _beaconResult = data;
            });
            print("Beacons DataReceived: " + data);
          }
        },
        onDone: () {},
        onError: (error) {
          print("Error: $error");
        });

Stop Listening to Beacons

     await BeaconsPlugin.stopMonitoring();

Run in Background

    //Send 'true' to run in background
     await BeaconsPlugin.runInBackground(true);

Clear Regions

    await BeaconsPlugin.clearRegions();

Add custom beacons layout (AltBeacon)

    BeaconsPlugin.addBeaconLayoutForAndroid(
            "m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");

Add custom Foreground scan periods (AltBeacon)

    BeaconsPlugin.setForegroundScanPeriodForAndroid(
            foregroundScanPeriod: 2200, foregroundBetweenScanPeriod: 10);

Add custom Background scan periods (AltBeacon)

    BeaconsPlugin.setBackgroundScanPeriodForAndroid(
            backgroundScanPeriod: 2200, backgroundBetweenScanPeriod: 10);

Set the level of debug messages

    //Valid values: 0 = no messages, 1 = errors, 2 = all messages
    await BeaconsPlugin.setDebugLevel(int value);

Set Prominent Disclosure message (Android 10)

See: Link

    if (Platform.isAndroid) {
    
      //Prominent disclosure
      await BeaconsPlugin.setDisclosureDialogMessage(
          title: "Need Location Permission",
          message: "This app collects location data to work with beacons.");

      //Only in case, you want the dialog to be shown again. By Default, dialog will never be shown if permissions are granted.
      await BeaconsPlugin.clearDisclosureDialogShowFlag(false);
    }

    BeaconsPlugin.channel.setMethodCallHandler((call) async {
        if (call.method == 'isPermissionDialogShown') {
          //Do something here
        }
    });

Scan Results

Data Android iOS
name Yes Yes
uuid Yes Yes
major Yes Yes
minor Yes Yes
distance Yes Yes
proximity Yes Yes
rssi Yes Yes
macAddress Yes No
txPower Yes No

Native Libraries

Author

Flutter Beacons plugin is developed by Umair Adil. You can email me at <m.umair.adil@gmail.com> for any queries.

Support

Buy a coffe to Umair Adil, creator of this plugin.

Buy me a coffee

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。