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:
// if you need to monitor also major and minor use the original version and not this forkBeaconsPlugin.addRegion("myBeacon", "01022022-f88f-0000-00ae-9605fd9bb620")
.then((result) {
print(result);
});
//Send 'true' to run in background [OPTIONAL]awaitBeaconsPlugin.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') {
awaitBeaconsPlugin.startMonitoring();
}
});
} elseif (Platform.isIOS) {
awaitBeaconsPlugin.startMonitoring();
}
if (Platform.isAndroid) {
//Prominent disclosureawaitBeaconsPlugin.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.awaitBeaconsPlugin.clearDisclosureDialogShowFlag(false);
}
BeaconsPlugin.channel.setMethodCallHandler((call) async {
if (call.method == 'isPermissionDialogShown') {
//Do something here
}
});