Skip to content

Commit

Permalink
#22 added equivalent method for monitoredRegions with CLManager
Browse files Browse the repository at this point in the history
  • Loading branch information
sameerdhulap committed Jun 20, 2024
1 parent 2008511 commit 4419f9c
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion Sources/WoosmapGeofencing/Business Logic/RegionMonitoring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ extension CLRegion {
}

protocol RegionMonitoring{

@available(iOS 17.0, *)
func monitoredRegions() async ->[CLRegion]

@available(iOS 17.0, *)
func list() async -> [String: CLCondition]

Expand Down Expand Up @@ -73,7 +77,6 @@ protocol RegionMonitoringDelegate {
class RegionMonitoringImpl: NSObject,RegionMonitoring{
var delegate: RegionMonitoringDelegate?
var monitor: CLMonitor?

init(_ event:RegionMonitoringDelegate){
super.init()
delegate = event
Expand Down Expand Up @@ -263,5 +266,33 @@ class RegionMonitoringImpl: NSObject,RegionMonitoring{
}
return output
}

func monitoredRegions() async ->[CLRegion] {
let listMonitor = await self.list()
var monitorArea:[CLRegion] = []
for (regionKey, region) in listMonitor{
if let circularRegion = region as? CLMonitor.CircularGeographicCondition{
let circularRegion: CLCircularRegion = CLCircularRegion(center: circularRegion.center, radius: circularRegion.radius, identifier: regionKey)
monitorArea.append(circularRegion)
}
else if let beaconRegion = region as? CLMonitor.BeaconIdentityCondition{
var beaconRegion: CLBeaconRegion = CLBeaconRegion(uuid: beaconRegion.uuid, identifier: regionKey)
if(beaconRegion.major != nil && beaconRegion.minor != nil){
beaconRegion = CLBeaconRegion(uuid: beaconRegion.uuid,
major: CLBeaconMajorValue(beaconRegion.major?.int16Value ?? 0),
minor: CLBeaconMinorValue(beaconRegion.minor?.int16Value ?? 0),
identifier: regionKey)
}
else if(beaconRegion.major != nil){
beaconRegion = CLBeaconRegion(uuid: beaconRegion.uuid,
major: CLBeaconMajorValue(beaconRegion.major?.int16Value ?? 0),
identifier: regionKey)
}
monitorArea.append(beaconRegion)
}
}
return monitorArea

}
}

0 comments on commit 4419f9c

Please sign in to comment.