Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added requestStateForRegion after didStartMonitoringForRegion on iOS #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/ios/GeofencePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ func log(message: String){
NSLog("%@ - %@", TAG, message)
}

func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}

@available(iOS 8.0, *)
@objc(HWPGeofencePlugin) class GeofencePlugin : CDVPlugin {
lazy var geoNotificationManager = GeoNotificationManager()
Expand Down Expand Up @@ -184,10 +193,12 @@ class GeofenceFaker {
dispatch_async(dispatch_get_main_queue()) {
if let region = self.geoNotificationManager.getMonitoredRegion(id) {
log("FAKER Trigger didEnterRegion")
/*
self.geoNotificationManager.locationManager(
self.geoNotificationManager.locationManager,
didEnterRegion: region
)
*/
}
}
}
Expand Down Expand Up @@ -332,6 +343,7 @@ class GeoNotificationManager : NSObject, CLLocationManagerDelegate {
log("deferred fail error: \(error)")
}

/*
func locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion) {
log("Entering region \(region.identifier)")
handleTransition(region, transitionType: 1)
Expand All @@ -341,17 +353,35 @@ class GeoNotificationManager : NSObject, CLLocationManagerDelegate {
log("Exiting region \(region.identifier)")
handleTransition(region, transitionType: 2)
}
*/

func locationManager(manager: CLLocationManager, didStartMonitoringForRegion region: CLRegion) {
let lat = (region as! CLCircularRegion).center.latitude
let lng = (region as! CLCircularRegion).center.longitude
let radius = (region as! CLCircularRegion).radius

log("Starting monitoring for region \(region) lat \(lat) lng \(lng) of radius \(radius)")
delay(0.2) {
log("Requesting State for region \(region) lat \(lat) lng \(lng)")
manager.requestStateForRegion(region)
}
}

func locationManager(manager: CLLocationManager, didDetermineState state: CLRegionState, forRegion region: CLRegion) {
log("State for region " + region.identifier)

if state == CLRegionState.Inside {
log("In \(region.identifier)")
handleTransition(region, transitionType: 1)
}
else if state == CLRegionState.Outside {
log("Not in \(region.identifier)")
handleTransition(region, transitionType: 2)
}
else {
log("Not determined")
}

}

func locationManager(manager: CLLocationManager, monitoringDidFailForRegion region: CLRegion?, withError error: NSError) {
Expand Down