根据需要自动将当前位置注册为地理围栏

时间:2014-07-02 15:24:46

标签: ios objective-c geofencing clregion clcircleregion

我的代码应该做这样的事情:

使用此方法将当前位置(使用显着位置更改)注册为200米半径的地理围栏:

- (void)startMonitoringRegionWithCoordinate:(CLLocationCoordinate2D)coordinate

当用户退出地理围栏时 - 再次注册其当前位置并发送到服务器

这种情况不会发生,有时它的工作效果不如预期,有时距离很远,效果很差。

  • 我试图找出自动注册地理围栏方法的问题。
  • 我也想弄明白,也许重要的地点变化让它搞得一团糟?

我一直试图将半径改为100-250米并且结果相同,退出地理围栏事件的频繁发生并不像预期的那样发生。

我错过了什么?

代码:

- (CLLocationDistance)preferableRadius
{
    CLLocationDistance radius = (CLLocationDistance)[defaults doubleForKey:kPREFERABLE_RADIUS_KEY];

    if (radius == 0.0) {
        [defaults setDouble:kFixedRadius forKey:kPREFERABLE_RADIUS_KEY];
        [defaults synchronize];

        radius = kFixedRadius;
    }
    else if (radius == kFixedRadius) {
        radius = kFixedRadius;
    }
    else {
        // Emergency mode, set radius to 100 meters
        [defaults setDouble:kFixedRadiusEmergency forKey:kPREFERABLE_RADIUS_KEY];
        [defaults synchronize];

        radius = kFixedRadiusEmergency;
    }

    return (radius > self.locationManager.maximumRegionMonitoringDistance) ? kFixedRadius : radius;
}

- (void)handleDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.launchOptions = launchOptions;
}

- (BOOL)isMonitoringActivated
{
    return self.locationManager.monitoredRegions.allObjects.count > 0;
}

- (void)deactivateMonitoring
{
    for (CLCircularRegion *region in self.locationManager.monitoredRegions) {
        [self.locationManager stopMonitoringForRegion:region];
    }
}

- (CLCircularRegion *)returnGeofenceByUniqueID:(NSString *)geofenceID
{
    for (CLCircularRegion *region in self.locationManager.monitoredRegions) {
        if ([region.identifier isEqualToString:geofenceID]) {
            return region;
        }
    }

    return nil;
}

- (void)deleteGeofenceWithUniqieID:(NSString *)geofenceID
{
    for (CLCircularRegion *region in self.locationManager.monitoredRegions) {
        if ([region.identifier isEqualToString:geofenceID]) {
            [self.locationManager stopMonitoringForRegion:region];
        }
    }
}

- (void)startMonitoringRegionWithCoordinate:(CLLocationCoordinate2D)coordinate
{
    [self startMonitoringRegionWithCoordinate:coordinate andRadius:kPREFERED_RADIUS];
}

- (void)startMonitoringRegionWithCoordinate:(CLLocationCoordinate2D)coordinate andRadius:(CLLocationDirection)radius
{
    NSLog(@"%s", __PRETTY_FUNCTION__);

    if ([self isMonitoringActivated]) {
        [self deactivateMonitoring];
    }

    CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:coordinate
                                                                 radius:radius
                                                             identifier:[self identifierForCoordinate:coordinate]];
    if (region) {
        CLLocation *lastLocation = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
        [self setLocation:lastLocation];

        [self.locationManager startMonitoringForRegion:region];
        [self.locationManager requestStateForRegion:region];
    }
    else NSLog(@"%s, region is nil, %@", __PRETTY_FUNCTION__, region);
}

- (NSArray *)sortedRegionsByDate
{
    NSArray *regions = self.locationManager.monitoredRegions.allObjects;
    NSArray *regionsNew = [regions sortedArrayUsingComparator:^NSComparisonResult(CLCircularRegion *obj1, CLCircularRegion *obj2) {
        NSDate *date1 = (NSDate *)obj1.identifier;
        NSDate *date2 = (NSDate *)obj2.identifier;

        return [date1 compare:date2];
    }];
    return regionsNew;
}

- (void)startMonitoringSignificantLocationChanges
{
    [self.locationManager startMonitoringSignificantLocationChanges];
}

- (void)stopMonitoringSignificantLocationChanges
{
    [self.locationManager stopMonitoringSignificantLocationChanges];
}

- (NSString *)identifierForCoordinate:(CLLocationCoordinate2D)coordinate
{
    return [NSString stringWithFormat:@"%@", [NSDate date]];
}

FOUNDATION_EXPORT NSString *NSStringFromCLRegionState(CLRegionState state)
{
    if (state == CLRegionStateUnknown) {
        return @"CLRegionStateUnknown";
    } else if (state == CLRegionStateInside) {
        return @"CLRegionStateInside";
    } else if (state == CLRegionStateOutside) {
        return @"CLRegionStateOutside";
    } else {
        return [NSString stringWithFormat:@"Undeterminded CLRegionState"];
    }
}

- (void)verifyAndSendLastLocation:(CLLocation *)lastLocation
{
    NSLog(@"verifyAndSendLastLocation, %@", lastLocation);

    CLLocation *oldLocation = [self getLocation];

    if (lastLocation && oldLocation) { // New & old location are good
        NSTimeInterval seconds = [oldLocation.timestamp timeIntervalSinceDate:lastLocation.timestamp]; // Calculate how seconds passed
        NSTimeInterval minutes = fabs(seconds) / 60; // Calculate how minutes passed

        BOOL isSameCoordinate =
        (oldLocation.coordinate.latitude == lastLocation.coordinate.latitude) &&
        (oldLocation.coordinate.longitude == lastLocation.coordinate.longitude) ? YES : NO;

        CLLocationDistance distance = [lastLocation distanceFromLocation:oldLocation];

        NSLog(@"validateLastLocation, location: %@,  minutes: %ld, distance: %f", lastLocation, (long)minutes, distance);

        // Distance > 200 or 30 minutes passed or coordinates are different
        if (distance >= 200.0 || minutes >= 30.0 || !isSameCoordinate) {
            NSLog(@"Distance > 200 or 30 minutes passed or coordinates are different");
            [[ServerApiManager sharedInstance] saveLocation:lastLocation]; // Send location to server
        }
    }
    else { // We just starting location updates
        NSLog(@"We just starting location updates");
        [[ServerApiManager sharedInstance] saveLocation:lastLocation]; // Send new location to server
    }
}

- (CLLocation *)getLocation
{
    return [self unarchiveLocationForKey:kLAST_LOCATION_KEY];
}

- (CLLocation *)unarchiveLocationForKey:(NSString *)key
{
    NSData *unarchivedData = [defaults objectForKey:key];
    return (CLLocation *)[NSKeyedUnarchiver unarchiveObjectWithData:unarchivedData];
}

- (BOOL)setLocation:(CLLocation *)lastLocation
{
    return [self archiveLocation:lastLocation toDeviceWithKey:kLAST_LOCATION_KEY];
}

- (BOOL)archiveLocation:(CLLocation *)location toDeviceWithKey:(NSString *)key
{
    NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:location];
    [defaults setObject:archivedData forKey:key];
    return [defaults synchronize];
}

#pragma mark - CLLocationManagerDelegate Methods

- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
    if (error.domain != kCLErrorDomain || error.code != 5/*) && [manager.monitoredRegions containsObject:region]*/) {
        NSLog(@"monitoringDidFailForRegion, error: %@", error.localizedDescription);
        NSLog(@"monitoringDidFailForRegion [manager.monitoredRegions containsObject:region]=%@"
              ,[manager.monitoredRegions containsObject:region]?@"yes":@"No");
        NSLog(@"monitoringDidFailForRegion, regions before: %lu", (unsigned long)manager.monitoredRegions.allObjects.count);

    }

    if (manager.monitoredRegions.allObjects.count >= 19) {
        [self startMonitoringRegionWithCoordinate:manager.location.coordinate];
    }
}

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
    if (![CLLocationManager locationServicesEnabled] || status == kCLAuthorizationStatusDenied || status == kCLAuthorizationStatusRestricted) {
        if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) return;

        dispatch_async(dispatch_get_main_queue(), ^{
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:MFLocalizedString(@"mobile_control_team", nil)
                                                                message:MFLocalizedString(@"gps_and_wifi_text", nil)
                                                               delegate:self
                                                      cancelButtonTitle:MFLocalizedString(@"ok", nil)
                                                      otherButtonTitles:nil];
            [alertView show];
        });
    }
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    NSLog(@"didUpdateLocations: %@", locations);
    CLLocation *lastLocation = (CLLocation *)locations.lastObject;
    CLLocationCoordinate2D coordinate = lastLocation.coordinate;

    if (lastLocation == nil || coordinate.latitude  == 0.0 || coordinate.longitude == 0.0) return;

    NSLog(@"didUpdateLocations, save location from didUpdateLocations.");

    [self startMonitoringRegionWithCoordinate:coordinate];
    [self verifyAndSendLastLocation:lastLocation];
}

- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
    NSLog(@"didStartMonitoringForRegion: %@", region);
    [manager requestStateForRegion:region];
}

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
    NSLog(@"didDetermineState, currentLocation: {%f, %f}, regionState: %@, region: %@",
          manager.location.coordinate.latitude, manager.location.coordinate.longitude, NSStringFromCLRegionState(state), region);
}

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
    NSLog(@"didEnterRegion: %@", region);
}

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
    NSTimeInterval minutes = ([UIApplication sharedApplication].backgroundTimeRemaining/60);

    NSLog(@"didExitRegion, applicationState: %@, backgroundTimeRemaining(minutes): %f",
          NSStringFromUIApplicationState([UIApplication sharedApplication].applicationState), minutes);

    CLLocation *lastLocation = manager.location;
    if (lastLocation == nil || lastLocation.coordinate.latitude  == 0.0 || lastLocation.coordinate.longitude == 0.0) return;

    NSLog(@"didExitRegion, save location from geofence.");
    [self startMonitoringRegionWithCoordinate:lastLocation.coordinate];
    [self verifyAndSendLastLocation:lastLocation];

}

1 个答案:

答案 0 :(得分:0)

最终我尝试了一个新项目并对其进行了测试:

[[Geofence sharedInstance] startUpdatingLocation];

Geofence.h

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

@interface Geofence : NSObject <CLLocationManagerDelegate>
@property (strong, nonatomic) CLLocationManager *locationManager;
+ (Geofence *)sharedInstance;
- (void)startUpdatingLocation;
- (void)deactiveMonitoring;
FOUNDATION_EXPORT void GeneratelPushNotification(NSString *text);
@end

Geofence.m

#import "Geofence.h"

    @implementation Geofence

    + (Geofence *)sharedInstance
    {
        static Geofence *instance;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            instance = [[Geofence alloc] init];
        });
        return instance;
    }

    - (instancetype)init
    {
        self = [super init];
        if (!self) {
            return nil;
        }

        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        self.locationManager.distanceFilter = kCLDistanceFilterNone;
        self.locationManager.delegate = self;

        return self;
    }

    FOUNDATION_EXPORT void GeneratelPushNotification(NSString *text)
    {
        UILocalNotification *localNotif = [[UILocalNotification alloc] init];
        localNotif.fireDate = [NSDate date];
        localNotif.timeZone = [NSTimeZone defaultTimeZone];
        localNotif.alertBody = text;
        localNotif.alertAction = NSLocalizedString(@"ok", nil);
        localNotif.soundName = UILocalNotificationDefaultSoundName;
        localNotif.userInfo = nil;
        [[UIApplication sharedApplication] presentLocalNotificationNow:localNotif];
    }

    - (void)startUpdatingLocation
    {
        [self.locationManager startUpdatingLocation];
    }

    - (void)deactiveMonitoring
    {
        NSLog(@"deactiveMonitoring");

        if (self.locationManager.monitoredRegions.allObjects.count > 0) {
            NSLog(@"more then 0 regions");
            for (CLRegion *region in self.locationManager.monitoredRegions) {
                NSLog(@"cancel region");
                [self.locationManager stopMonitoringForRegion:region];
            }
        }
    }

    - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
    {
        CLLocation *currentLocation = locations.lastObject;
        NSLog(@"didUpdateLocations, currentLocation: %@", currentLocation);

        if (currentLocation && currentLocation.coordinate.latitude != 0.0 && currentLocation.coordinate.longitude != 0.0) {
            NSLog(@"didUpdateLocations, location is valid.");

            [self deactiveMonitoring];

            NSString *regionIdentifier = [[NSDate date] description];
            CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:currentLocation.coordinate radius:100 identifier:regionIdentifier];
            [manager startMonitoringForRegion:region];
            [manager stopUpdatingLocation];

            NSLog(@"didUpdateLocations, end of if.");
        }
    }

    - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
    {
        NSLog(@"didDetermineState, state: %d, region: %@", state, region);
    }

    - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
    {
        NSLog(@"didEnterRegion, region: %@", region);
    }

    - (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
    {
        NSLog(@"didStartMonitoringForRegion, region: %@", region);
    }

    - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
    {
        NSLog(@"didExitRegion: %@", region);

        CLLocation *oldRegionLocation = [[CLLocation alloc] initWithLatitude:region.center.latitude longitude:region.center.longitude];
        CLLocation *currentLocation = manager.location;
        NSLog(@"didExitRegion, currentLocation: %@", currentLocation);

        CLLocationDistance distanceBetween = [currentLocation distanceFromLocation:oldRegionLocation];
        NSLog(@"didExitRegion, distanceBetween: %f", distanceBetween);

        GeneratelPushNotification([NSString stringWithFormat:@"didExitRegion: {%f, %f}, distance: %f",
                                   region.center.latitude, region.center.longitude, distanceBetween]);

        [self deactiveMonitoring];

        if (currentLocation && currentLocation.coordinate.latitude != 0.0 && currentLocation.coordinate.longitude != 0.0) {
            NSLog(@"didExitRegion, location is valid.");

            NSString *regionIdentifier = [[NSDate date] description];
            CLCircularRegion *newRegion = [[CLCircularRegion alloc] initWithCenter:currentLocation.coordinate radius:100 identifier:regionIdentifier];
            [manager startMonitoringForRegion:newRegion];
            NSLog(@"didExitRegion, end of if.");
        }
    }

    @end

登录iPhone 4,iOS 7.1.2,应用程序未运行:

2014-07-03 10:03:07.863 Geofence[449:60b] didUpdateLocations, currentLocation: <+31.24189568,+34.78870079> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:03:07 Israel Daylight Time
2014-07-03 10:03:07.878 Geofence[449:60b] didUpdateLocations, location is valid.
2014-07-03 10:03:07.886 Geofence[449:60b] deactiveMonitoring
2014-07-03 10:03:07.926 Geofence[449:60b] didUpdateLocations, end of if.
2014-07-03 10:03:07.962 Geofence[449:60b] didUpdateLocations, currentLocation: <+31.24189568,+34.78870079> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:03:07 Israel Daylight Time
2014-07-03 10:03:07.972 Geofence[449:60b] didUpdateLocations, location is valid.
2014-07-03 10:03:07.974 Geofence[449:60b] deactiveMonitoring
2014-07-03 10:03:08.028 Geofence[449:60b] more then 0 regions
2014-07-03 10:03:08.088 Geofence[449:60b] cancel region
2014-07-03 10:03:08.092 Geofence[449:60b] didUpdateLocations, end of if.
2014-07-03 10:03:08.096 Geofence[449:60b] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:03:07 +0000', center:<+31.24189568,+34.78870079>, radius:100.00m)
2014-07-03 10:03:08.489 Geofence[449:60b] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:03:08 +0000', center:<+31.24189568,+34.78870079>, radius:100.00m)
2014-07-03 10:13:16.946 Geofence[486:707] didExitRegion: CLCircularRegion (identifier:'2014-07-03 07:03:07 +0000', center:<+31.24189568,+34.78870079>, radius:100.00m)
2014-07-03 10:13:16.983 Geofence[486:707] didExitRegion, currentLocation: <+31.24067170,+34.79051177> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:13:16 Israel Daylight Time
2014-07-03 10:13:16.992 Geofence[486:707] didExitRegion, distanceBetween: 219.498320
2014-07-03 10:13:17.011 Geofence[486:707] deactiveMonitoring
2014-07-03 10:13:17.651 Geofence[486:707] more then 0 regions
2014-07-03 10:13:17.661 Geofence[486:707] cancel region
2014-07-03 10:13:17.709 Geofence[486:707] didExitRegion, location is valid.
2014-07-03 10:13:17.723 Geofence[486:707] didExitRegion, end of if.
2014-07-03 10:13:17.916 Geofence[486:707] didDetermineState, state: 2, region: CLCircularRegion (identifier:'2014-07-03 07:03:07 +0000', center:<+31.24189568,+34.78870079>, radius:100.00m)
2014-07-03 10:13:17.922 Geofence[486:707] didExitRegion: CLCircularRegion (identifier:'2014-07-03 07:03:08 +0000', center:<+31.24189568,+34.78870079>, radius:100.00m)
2014-07-03 10:13:17.929 Geofence[486:707] didExitRegion, currentLocation: <+31.24067170,+34.79051177> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:13:16 Israel Daylight Time
2014-07-03 10:13:17.993 Geofence[486:707] didExitRegion, distanceBetween: 219.498320
2014-07-03 10:13:18.404 Geofence[486:707] deactiveMonitoring
2014-07-03 10:13:18.416 Geofence[486:707] more then 0 regions
2014-07-03 10:13:18.435 Geofence[486:707] cancel region
2014-07-03 10:13:18.445 Geofence[486:707] didExitRegion, location is valid.
2014-07-03 10:13:18.470 Geofence[486:707] didExitRegion, end of if.
2014-07-03 10:13:18.636 Geofence[486:707] didDetermineState, state: 2, region: CLCircularRegion (identifier:'2014-07-03 07:03:08 +0000', center:<+31.24189568,+34.78870079>, radius:100.00m)
2014-07-03 10:13:18.696 Geofence[486:707] didUpdateLocations, currentLocation: <+31.24067179,+34.79051129> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:13:16 Israel Daylight Time
2014-07-03 10:13:18.705 Geofence[486:707] didUpdateLocations, location is valid.
2014-07-03 10:13:18.712 Geofence[486:707] deactiveMonitoring
2014-07-03 10:13:18.731 Geofence[486:707] more then 0 regions
2014-07-03 10:13:18.753 Geofence[486:707] cancel region
2014-07-03 10:13:18.769 Geofence[486:707] didUpdateLocations, end of if.
2014-07-03 10:13:19.063 Geofence[486:707] didUpdateLocations, currentLocation: <+31.24067179,+34.79051129> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:13:16 Israel Daylight Time
2014-07-03 10:13:19.086 Geofence[486:707] didUpdateLocations, location is valid.
2014-07-03 10:13:19.093 Geofence[486:707] deactiveMonitoring
2014-07-03 10:13:19.102 Geofence[486:707] more then 0 regions
2014-07-03 10:13:19.115 Geofence[486:707] cancel region
2014-07-03 10:13:19.128 Geofence[486:707] didUpdateLocations, end of if.
2014-07-03 10:13:19.469 Geofence[486:707] didUpdateLocations, currentLocation: <+31.24067111,+34.79051330> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:13:16 Israel Daylight Time
2014-07-03 10:13:19.476 Geofence[486:707] didUpdateLocations, location is valid.
2014-07-03 10:13:19.481 Geofence[486:707] deactiveMonitoring
2014-07-03 10:13:19.494 Geofence[486:707] more then 0 regions
2014-07-03 10:13:19.518 Geofence[486:707] cancel region
2014-07-03 10:13:19.622 Geofence[486:707] didUpdateLocations, end of if.
2014-07-03 10:13:19.636 Geofence[486:707] didUpdateLocations, currentLocation: <+31.24067170,+34.79051177> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:13:16 Israel Daylight Time
2014-07-03 10:13:19.644 Geofence[486:707] didUpdateLocations, location is valid.
2014-07-03 10:13:19.670 Geofence[486:707] deactiveMonitoring
2014-07-03 10:13:19.742 Geofence[486:707] more then 0 regions
2014-07-03 10:13:20.016 Geofence[486:707] cancel region
2014-07-03 10:13:20.042 Geofence[486:707] didUpdateLocations, end of if.
2014-07-03 10:13:20.049 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:13:17 +0000', center:<+31.24067170,+34.79051177>, radius:100.00m)
2014-07-03 10:13:20.054 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:13:18 +0000', center:<+31.24067170,+34.79051177>, radius:100.00m)
2014-07-03 10:13:20.085 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:13:18 +0000', center:<+31.24067179,+34.79051129>, radius:100.00m)
2014-07-03 10:13:20.232 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:13:19 +0000', center:<+31.24067179,+34.79051129>, radius:100.00m)
2014-07-03 10:13:20.401 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:13:19 +0000', center:<+31.24067111,+34.79051330>, radius:100.00m)
2014-07-03 10:13:20.414 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:13:20 +0000', center:<+31.24067170,+34.79051177>, radius:100.00m)
2014-07-03 10:17:02.317 Geofence[486:707] didExitRegion: CLCircularRegion (identifier:'2014-07-03 07:13:20 +0000', center:<+31.24067170,+34.79051177>, radius:100.00m)
2014-07-03 10:17:02.419 Geofence[486:707] didExitRegion, currentLocation: <+31.23952719,+34.79196977> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:17:02 Israel Daylight Time
2014-07-03 10:17:02.435 Geofence[486:707] didExitRegion, distanceBetween: 188.134236
2014-07-03 10:17:02.681 Geofence[486:707] deactiveMonitoring
2014-07-03 10:17:02.697 Geofence[486:707] more then 0 regions
2014-07-03 10:17:02.730 Geofence[486:707] cancel region
2014-07-03 10:17:02.745 Geofence[486:707] didExitRegion, location is valid.
2014-07-03 10:17:02.752 Geofence[486:707] didExitRegion, end of if.
2014-07-03 10:17:02.762 Geofence[486:707] didDetermineState, state: 2, region: CLCircularRegion (identifier:'2014-07-03 07:13:20 +0000', center:<+31.24067170,+34.79051177>, radius:100.00m)
2014-07-03 10:17:02.894 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:17:02 +0000', center:<+31.23952719,+34.79196977>, radius:100.00m)
2014-07-03 10:20:42.460 Geofence[486:707] didExitRegion: CLCircularRegion (identifier:'2014-07-03 07:17:02 +0000', center:<+31.23952719,+34.79196977>, radius:100.00m)
2014-07-03 10:20:42.593 Geofence[486:707] didExitRegion, currentLocation: <+31.23803334,+34.79391603> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:20:42 Israel Daylight Time
2014-07-03 10:20:42.597 Geofence[486:707] didExitRegion, distanceBetween: 248.616173
2014-07-03 10:20:42.829 Geofence[486:707] deactiveMonitoring
2014-07-03 10:20:42.845 Geofence[486:707] more then 0 regions
2014-07-03 10:20:42.876 Geofence[486:707] cancel region
2014-07-03 10:20:42.896 Geofence[486:707] didExitRegion, location is valid.
2014-07-03 10:20:42.912 Geofence[486:707] didExitRegion, end of if.
2014-07-03 10:20:42.917 Geofence[486:707] didDetermineState, state: 2, region: CLCircularRegion (identifier:'2014-07-03 07:17:02 +0000', center:<+31.23952719,+34.79196977>, radius:100.00m)
2014-07-03 10:20:43.047 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:20:42 +0000', center:<+31.23803334,+34.79391603>, radius:100.00m)
2014-07-03 10:24:32.434 Geofence[486:707] didExitRegion: CLCircularRegion (identifier:'2014-07-03 07:20:42 +0000', center:<+31.23803334,+34.79391603>, radius:100.00m)
2014-07-03 10:24:32.476 Geofence[486:707] didExitRegion, currentLocation: <+31.23773124,+34.79202236> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:24:32 Israel Daylight Time
2014-07-03 10:24:32.490 Geofence[486:707] didExitRegion, distanceBetween: 183.486002
2014-07-03 10:24:32.523 Geofence[486:707] deactiveMonitoring
2014-07-03 10:24:32.743 Geofence[486:707] more then 0 regions
2014-07-03 10:24:32.775 Geofence[486:707] cancel region
2014-07-03 10:24:32.788 Geofence[486:707] didExitRegion, location is valid.
2014-07-03 10:24:32.804 Geofence[486:707] didExitRegion, end of if.
2014-07-03 10:24:32.808 Geofence[486:707] didDetermineState, state: 2, region: CLCircularRegion (identifier:'2014-07-03 07:20:42 +0000', center:<+31.23803334,+34.79391603>, radius:100.00m)
2014-07-03 10:24:32.942 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:24:32 +0000', center:<+31.23773124,+34.79202236>, radius:100.00m)
2014-07-03 10:28:48.125 Geofence[486:707] didExitRegion: CLCircularRegion (identifier:'2014-07-03 07:24:32 +0000', center:<+31.23773124,+34.79202236>, radius:100.00m)
2014-07-03 10:28:48.233 Geofence[486:707] didExitRegion, currentLocation: <+31.23925385,+34.78998077> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:28:48 Israel Daylight Time
2014-07-03 10:28:48.290 Geofence[486:707] didExitRegion, distanceBetween: 257.540389
2014-07-03 10:28:48.550 Geofence[486:707] deactiveMonitoring
2014-07-03 10:28:48.575 Geofence[486:707] more then 0 regions
2014-07-03 10:28:48.593 Geofence[486:707] cancel region
2014-07-03 10:28:48.619 Geofence[486:707] didExitRegion, location is valid.
2014-07-03 10:28:48.634 Geofence[486:707] didExitRegion, end of if.
2014-07-03 10:28:48.639 Geofence[486:707] didDetermineState, state: 2, region: CLCircularRegion (identifier:'2014-07-03 07:24:32 +0000', center:<+31.23773124,+34.79202236>, radius:100.00m)
2014-07-03 10:28:48.742 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:28:48 +0000', center:<+31.23925385,+34.78998077>, radius:100.00m)
2014-07-03 10:32:29.427 Geofence[486:707] didExitRegion: CLCircularRegion (identifier:'2014-07-03 07:28:48 +0000', center:<+31.23925385,+34.78998077>, radius:100.00m)
2014-07-03 10:32:29.474 Geofence[486:707] didExitRegion, currentLocation: <+31.24078335,+34.78924175> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:32:29 Israel Daylight Time
2014-07-03 10:32:29.477 Geofence[486:707] didExitRegion, distanceBetween: 183.614558
2014-07-03 10:32:29.684 Geofence[486:707] deactiveMonitoring
2014-07-03 10:32:29.710 Geofence[486:707] more then 0 regions
2014-07-03 10:32:29.732 Geofence[486:707] cancel region
2014-07-03 10:32:29.750 Geofence[486:707] didExitRegion, location is valid.
2014-07-03 10:32:29.762 Geofence[486:707] didExitRegion, end of if.
2014-07-03 10:32:29.772 Geofence[486:707] didDetermineState, state: 2, region: CLCircularRegion (identifier:'2014-07-03 07:28:48 +0000', center:<+31.23925385,+34.78998077>, radius:100.00m)
2014-07-03 10:32:29.928 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:32:29 +0000', center:<+31.24078335,+34.78924175>, radius:100.00m)
2014-07-03 10:34:30.808 Geofence[486:707] didEnterRegion, region: CLCircularRegion (identifier:'2014-07-03 07:03:07 +0000', center:<+31.24189568,+34.78870079>, radius:100.00m)
2014-07-03 10:34:30.834 Geofence[486:707] didDetermineState, state: 1, region: CLCircularRegion (identifier:'2014-07-03 07:03:07 +0000', center:<+31.24189568,+34.78870079>, radius:100.00m)
2014-07-03 10:35:11.038 Geofence[486:707] didExitRegion: CLCircularRegion (identifier:'2014-07-03 07:03:07 +0000', center:<+31.24189568,+34.78870079>, radius:100.00m)
2014-07-03 10:35:11.135 Geofence[486:707] didExitRegion, currentLocation: <+31.24338224,+34.78568168> +/- 112.92m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:35:11 Israel Daylight Time
2014-07-03 10:35:11.152 Geofence[486:707] didExitRegion, distanceBetween: 331.485582
2014-07-03 10:35:11.190 Geofence[486:707] deactiveMonitoring
2014-07-03 10:35:11.467 Geofence[486:707] more then 0 regions
2014-07-03 10:35:11.495 Geofence[486:707] cancel region
2014-07-03 10:35:11.544 Geofence[486:707] didExitRegion, location is valid.
2014-07-03 10:35:11.552 Geofence[486:707] didExitRegion, end of if.
2014-07-03 10:35:11.557 Geofence[486:707] didDetermineState, state: 2, region: CLCircularRegion (identifier:'2014-07-03 07:03:07 +0000', center:<+31.24189568,+34.78870079>, radius:100.00m)
2014-07-03 10:35:11.562 Geofence[486:707] didExitRegion: CLCircularRegion (identifier:'2014-07-03 07:32:29 +0000', center:<+31.24078335,+34.78924175>, radius:100.00m)
2014-07-03 10:35:11.684 Geofence[486:707] didExitRegion, currentLocation: <+31.24338224,+34.78568168> +/- 112.92m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:35:11 Israel Daylight Time
2014-07-03 10:35:11.697 Geofence[486:707] didExitRegion, distanceBetween: 445.023446
2014-07-03 10:35:11.916 Geofence[486:707] deactiveMonitoring
2014-07-03 10:35:11.949 Geofence[486:707] more then 0 regions
2014-07-03 10:35:11.996 Geofence[486:707] cancel region
2014-07-03 10:35:12.012 Geofence[486:707] didExitRegion, location is valid.
2014-07-03 10:35:12.031 Geofence[486:707] didExitRegion, end of if.
2014-07-03 10:35:12.082 Geofence[486:707] didDetermineState, state: 2, region: CLCircularRegion (identifier:'2014-07-03 07:32:29 +0000', center:<+31.24078335,+34.78924175>, radius:100.00m)
2014-07-03 10:35:12.140 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:35:11 +0000', center:<+31.24338224,+34.78568168>, radius:100.00m)
2014-07-03 10:35:12.160 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:35:12 +0000', center:<+31.24338224,+34.78568168>, radius:100.00m)
2014-07-03 10:38:49.971 Geofence[486:707] didEnterRegion, region: CLCircularRegion (identifier:'2014-07-03 07:03:07 +0000', center:<+31.24189568,+34.78870079>, radius:100.00m)
2014-07-03 10:38:49.977 Geofence[486:707] didDetermineState, state: 1, region: CLCircularRegion (identifier:'2014-07-03 07:03:07 +0000', center:<+31.24189568,+34.78870079>, radius:100.00m)
2014-07-03 10:38:49.988 Geofence[486:707] didExitRegion: CLCircularRegion (identifier:'2014-07-03 07:35:12 +0000', center:<+31.24338224,+34.78568168>, radius:100.00m)
2014-07-03 10:38:50.040 Geofence[486:707] didExitRegion, currentLocation: <+31.24191178,+34.78860343> +/- 65.00m (speed -1.00 mps / course -1.00) @ 7/3/14, 10:38:50 Israel Daylight Time
2014-07-03 10:38:50.134 Geofence[486:707] didExitRegion, distanceBetween: 322.566301
2014-07-03 10:38:50.432 Geofence[486:707] deactiveMonitoring
2014-07-03 10:38:50.555 Geofence[486:707] more then 0 regions
2014-07-03 10:38:50.571 Geofence[486:707] cancel region
2014-07-03 10:38:50.587 Geofence[486:707] didExitRegion, location is valid.
2014-07-03 10:38:50.661 Geofence[486:707] didExitRegion, end of if.
2014-07-03 10:38:50.667 Geofence[486:707] didDetermineState, state: 2, region: CLCircularRegion (identifier:'2014-07-03 07:35:12 +0000', center:<+31.24338224,+34.78568168>, radius:100.00m)
2014-07-03 10:38:50.734 Geofence[486:707] didStartMonitoringForRegion, region: CLCircularRegion (identifier:'2014-07-03 07:38:50 +0000', center:<+31.24191178,+34.78860343>, radius:100.00m)

问题是: 假设用户关闭设备并在不同区域再次打开,设备不会监控当前位置,为此我假设我需要使用significantLocationChanges

但是我害怕使用significantLocationChanges会搞砸一些东西。