Skip to content

Commit

Permalink
Can clear regions.
Browse files Browse the repository at this point in the history
  • Loading branch information
gazialankus committed Jan 23, 2021
1 parent adc3e85 commit 66b6765
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open class BeaconHelper(var context: Context) : BeaconConsumer, BeaconsPlugin.Co
companion object {

@JvmStatic
private val listOfRegions = arrayListOf<Region>()
private var listOfRegions = arrayListOf<Region>()
}

private val TAG = "BeaconHelper"
Expand Down Expand Up @@ -191,6 +191,13 @@ open class BeaconHelper(var context: Context) : BeaconConsumer, BeaconsPlugin.Co
Log.i(TAG, "Region Added: ${region.uniqueId}, UUID: ${region.id1}")
}

override fun clearRegions(call: MethodCall, result: MethodChannel.Result) {
listOfRegions = arrayListOf<Region>()

result.success("Regions Cleared")
Log.i(TAG, "Regions Cleared")
}

override fun startScanning() {

setUpBLE(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class BeaconsPlugin : FlutterPlugin, ActivityAware, PluginRegistry.RequestPermis
call.method == "addRegion" -> {
callBack?.addRegion(call, result)
}
call.method == "clearRegions" -> {
callBack?.clearRegions(call, result)
}
call.method == "runInBackground" -> {
call.argument<Boolean>("background")?.let {
runInBackground = it
Expand Down Expand Up @@ -278,6 +281,7 @@ class BeaconsPlugin : FlutterPlugin, ActivityAware, PluginRegistry.RequestPermis
fun startScanning()
fun stopMonitoringBeacons()
fun addRegion(call: MethodCall, result: MethodChannel.Result)
fun clearRegions(call: MethodCall, result: MethodChannel.Result)
fun setEventSink(events: EventChannel.EventSink?)
}

Expand Down
7 changes: 7 additions & 0 deletions ios/Classes/SwiftBeaconsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public class SwiftBeaconsPlugin: NSObject, FlutterPlugin {
} else {
result("iOS could not extract flutter arguments in method: (addRegion)")
}
} else if call.method == "clearRegions"{
clearRegions()
result("Regions cleared.")
} else if call.method == "startMonitoring"{
locationManager.delegate = self
startScanning()
Expand Down Expand Up @@ -83,6 +86,10 @@ public class SwiftBeaconsPlugin: NSObject, FlutterPlugin {
listOfRegions.append(newItem)
}

func clearRegions() {
listOfRegions = [Item]()
}

func startMonitoringItem(_ item: Item) {
let beaconRegion = item.asBeaconRegion()
locationManager.startMonitoring(for: beaconRegion)
Expand Down
6 changes: 6 additions & 0 deletions lib/beacons_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class BeaconsPlugin {
return result;
}

static Future<String> clearRegions() async {
final String result = await channel.invokeMethod('clearRegions');
printDebugMessage(result, 2);
return result;
}

static Future<String> runInBackground(bool runInBackground) async {
final String result = await channel.invokeMethod(
'runInBackground',
Expand Down

0 comments on commit 66b6765

Please sign in to comment.