Reputation: 2224
I am trying to implement Geofencing with out iBeacon. The
didStartMonitoringFor
is getting called, but
didEnterRegion
& didDetermineState
not being called when the app is not running.
I am calling the requestState
in didStartMonitoringFor
. So the didDetermineState
is being called for the first time. But not getting called while location changes. Can some one help me ?
Thanks in advance !
Upvotes: 0
Views: 1523
Reputation: 2224
Thank God ! I got the answer by myself.
I have been doing all declaration and delegate method implementation in Home screen classs. I changed all part to AppDelegate
class. Also made some changes to properties for location manager as
locationManager.delegate = self
locationManager.activityType = .automotiveNavigation
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.distanceFilter = 10.0
locationManager.requestAlwaysAuthorization()
Also implemented both delegate methods
func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion){
manager.requestState(for: region)
}
func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {
if state == .inside
{
addNotification(region: region)
}
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
addNotification(region: region)
}
And it worked !
Upvotes: 1