beacons_plugin
이 플러그인은 Flutter 앱에서 근처의 iBeacon을 스캔하고 범위를 측정하는 것을 더 쉽게 만듭니다. 스캔된 비콘은 근접 값을 제공합니다.
iBeacon의 범위 및 모니터링을 위한 플러터 플러그인 프로젝트입니다.
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
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.
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.
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>
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';
// 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();
}
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");
});
await BeaconsPlugin.stopMonitoring();
//Send 'true' to run in background
await BeaconsPlugin.runInBackground(true);
await BeaconsPlugin.clearRegions();
BeaconsPlugin.addBeaconLayoutForAndroid(
"m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
BeaconsPlugin.setForegroundScanPeriodForAndroid(
foregroundScanPeriod: 2200, foregroundBetweenScanPeriod: 10);
BeaconsPlugin.setBackgroundScanPeriodForAndroid(
backgroundScanPeriod: 2200, backgroundBetweenScanPeriod: 10);
//Valid values: 0 = no messages, 1 = errors, 2 = all messages
await BeaconsPlugin.setDebugLevel(int value);
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
}
});
| 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 |
Flutter Beacons plugin is developed by Umair Adil. You can email me at <m.umair.adil@gmail.com> for any queries.
Buy a coffe to Umair Adil, creator of this plugin.
의존성 목록 2 개
{"sdk":"flutter"}{"sdk":"flutter"}사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗