패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.0.8

beacons_plugin

이 플러그인은 Flutter 앱에서 근처의 iBeacon을 스캔하고 범위를 측정하는 것을 더 쉽게 만듭니다. 스캔된 비콘은 근접 값을 제공합니다.

AndroidiOS
30일 다운로드
261
좋아요
64
Pub 점수
130

패키지 설치

flutter pub add beacons_plugin

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

beacons_plugin 플러그인은 Android 및 iOS용 Flutter 애플리케이션에서 iBeacon 스캔과 범위 측정을 간편하게 만듭니다. 개발자는 근처의 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

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.