kinamin
kinamin

Reputation: 127

CLLocationManager:didDetermineState:forRegion not called

I'm implementing iOS7 app using google maps SDK for iOS & region monitoring of CoreLocation framework. After registering monitoring region, calling requestStateForRegion method but I have no reaction on didDetermineState:forRegion method on device(iOS7.0.4, iPhone5S).

it can receive didUpdateLocation method, so I think delegation process is working fine. On simulator, didDetermineState:forRegion method called properly.

What should I do to fix this problem? initialization code is as follows.

Any advice appreciated. Thanks in advance.

- (void)viewDidLoad
{
    if (locManager == nil ) {
        locManager = [CLLocationManager new];
    }
    locManager.delegate = self;

    CLLocationCoordinate2D targetCenter;
    targetCenter.latitude = LATITUDE_CENTER;
    targetCenter.longitude = LONGITUDE_CENTER;
    CLLocationDegrees radius = TARGET_RADIUS;
    if ( locManager.maximumRegionMonitoringDistance < TARGET_RADIUS ){
        radius = locManager.maximumRegionMonitoringDistance;
    }
    self.targetRegion = [[CLCircularRegion alloc]
                     initWithCenter:targetCenter
                     radius:radius
                     identifier:@"TargetRegion"];

    BOOL monitoringAvailability = [CLLocationManager isMonitoringAvailableForClass:[self.targetRegion class]];
    if( monitoringAvailability ) {
        if( [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized ) {
            [locManager startMonitoringForRegion:self.targetRegion];
        }
    }

    [locManager requestStateForRegion:self.targetRegion];  
}

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
    if (state == CLRegionStateInside){
        NSLog(@"is in target region");
        self.isInTargetRegion = YES;
    }else{
        NSLog(@"is out of target region");
        self.isInTargetRegion = NO;
    }
}

Upvotes: 1

Views: 5934

Answers (3)

Bohdan
Bohdan

Reputation: 1

Implement this callback

(void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error

Upvotes: 0

Keller
Keller

Reputation: 17081

In iOS 8, you need to prompt for kCLAuthorizationStatusAuthorizedAlways using [CLLocationManager requestAlwaysAuthorization]. You will also need to have a NSLocationAlwaysUsageDescription entry in your Info.plist file.

Upvotes: 2

kinamin
kinamin

Reputation: 127

I found the answer myself.

on the iPhone device, Settings -> General -> Background App Refresh enable background app refresh of the app, then called didDetermineState properly.

Upvotes: 5

Related Questions