Geofencing didEnterRegion, didExitRegion function not call in iphone 5S iOS8.1

I debugged all day, and the delegate was generally called.

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region

Well here is my standard code calling the monitor. use CoreLocation.framework.

[locationManager startMonitoringForRegion:geofence];

And registered them in my plist.

<key>NSLocationAlwaysUsageDescription</key>
<string>Lugang</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Lugang</string>

Updating the background application in resolution, but I did not see my application inside.

I tried to print my controlled Regions in the LocationManager example, and there is my controlled area.

NSLog(@"%@" ,locationManager.monitoredRegions);

and regionMonitoringAvailable is true.

NSLog(@"%d" , [CLLocationManager regionMonitoringAvailable] );

In iOS 8, I asked for requestAlwaysAuthorization

[locationManager requestAlwaysAuthorization];

I tried three states, the application is in the foreground, the application is in the background, the application is inactive. none of these conditions were caused.

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error

there were no errors.

And I tried

[locationManager requestStateForRegion:geofence];

works great.

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region

activated in my requestStateForRegion.

, , didEnterRegion , , iOS 7 , , .

, requestStateForRegion , , DidEnterRegion . , .

+3
1

, , .

  • Array locationmanager. .

    for (CLRegion *monitored in [locationManagerGeofence monitoredRegions])
     {
         [locationManagerGeofence stopMonitoringForRegion:monitored];
     }
     self.geofencesArray = [NSMutableArray arrayWithArray:[self buildGeofenceData]];
     if([CLLocationManager regionMonitoringAvailable])
     {
         for (CLRegion *region in self.geofencesArray)
         {
             [locationManagerGeofence startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyBest];
         }
     }
     else
     {
         [BB_Global displayAlertWithTitle:@"" message:@"This app requires region monitoring features which are unavailable on this device."];
     }
    
  • , Wi-Fi .
  • .

    -(void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
    {
        NSLog(@"Started monitoring %@ region", region.identifier);
    }
    
  • . 1) DidEnter 2) DidExit

  • - (, 100 ). DidEnter DidExit, . , , - .
  • :)
+2

Source: https://habr.com/ru/post/1589136/


All Articles