Region Monitoring issues in IOS

2019-08-21 20:12发布

I am developing region monitoring from 4-5 months, and it was working fine before. Before a week or ago when we tested the code on device having IOS 7.1, we found an issue:

  • when one registered region is detected, it never getting detected again until user move far from this region by distance 10Km, if user never crosses this range of 10Km, no Enter/Exit events will be called for that region. If user travels far distance 10 Km from the detected region, its Exit event will be called, and when user comes back near the registered region, Enter event will be fired then only.

Here is my code: - i made a singleton of Location Manager, and initializing it in Location Manager:

    if (locationManager == nil)
    {
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.distanceFilter = kCLDistanceFilterNone;
        locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
        if ([locationManager respondsToSelector:@selector(activityType)])
        {
            [locationManager setActivityType:CLActivityTypeFitness];
        }

        if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
        {
            [locationManager requestAlwaysAuthorization];
        }
    }
  • Then i get user's current location and send it to server, to get nearby geofence regions, and register them to be monitored as follows:

    - (void)startRegionMonitoring:(NSArray*)regions
    {
        [self unregisterRegionMonitoring];
    
        if ([Helper isValidForRegionMonitoring])
        {
            [locationManager setDelegate:self];
            int MAX_REGION = regions.count > 20 ? 20 : regions.count;
    
            for (int index=0; index<MAX_REGION; index++)
            {
                NSString *identifier = [NSString stringWithFormat:@"Identfier %d", index+1];
                CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake([[[regions objectAtIndex:index] valueForKey:@"lat"] doubleValue],
                                                                             [[[regions objectAtIndex:index] valueForKey:@"lon"] doubleValue]);
    
                CLRegion *region = nil;
                double radius = 200.0;
    
                if ([Helper isIOS7])
                {
                    region = [[[CLCircularRegion alloc] initWithCenter:centerCoordinate
                                                        radius:radius
                                                    identifier:identifier] autorelease];
                }
                else
                {
                    region = [[[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate
                                                              radius:radius
                                                          identifier:identifier] autorelease];
                }
                    [locationManager startMonitoringForRegion:region];
            }
        }
    }
    

I tried different values of "distanceFilter", "DesiredAccuracy", and also played with different values for radius of monitored regions to fix the bug. but it didn't work.

0条回答
登录 后发表回答