From fe94de687623404a65d304d6c83422badf34b128 Mon Sep 17 00:00:00 2001 From: aYukoIzuhara Date: Thu, 29 Mar 2018 23:41:20 +0900 Subject: [PATCH 1/2] support kCLAuthorizationStatusAuthorizedWhenInUse --- iOS/ABFBeacon/ABFBeacon.m | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/iOS/ABFBeacon/ABFBeacon.m b/iOS/ABFBeacon/ABFBeacon.m index 6b13253..77251a0 100644 --- a/iOS/ABFBeacon/ABFBeacon.m +++ b/iOS/ABFBeacon/ABFBeacon.m @@ -11,6 +11,7 @@ @interface ABFBeacon () @property (nonatomic, strong) CBPeripheralManager *peripheralManager; @property (nonatomic, strong) CLLocationManager *locationManager; +@property (nonatomic) CLAuthorizationStatus authStatus; @end @implementation ABFBeacon @@ -67,6 +68,8 @@ - (instancetype)initSharedInstance name:UIApplicationDidBecomeActiveNotification object:nil]; */ + + _authStatus = [CLLocationManager authorizationStatus]; } return self; } @@ -140,11 +143,21 @@ - (BOOL)isMonitoringCapable - (void)updateMonitoring { + CLAuthorizationStatus newStatus = [CLLocationManager authorizationStatus]; + if ([self isMonitoringCapable]) { + if ((self.authStatus == kCLAuthorizationStatusAuthorizedAlways + && newStatus == kCLAuthorizationStatusAuthorizedWhenInUse) + || (self.authStatus = kCLAuthorizationStatusAuthorizedWhenInUse + && newStatus == kCLAuthorizationStatusAuthorizedAlways)) { + [self disableMonitoring]; + } [self enableMonitoring]; } else { [self disableMonitoring]; } + + self.authStatus = newStatus; } - (void)enableMonitoring @@ -178,7 +191,14 @@ - (void)enableMonitoringForRegion:(ABFBeaconRegion *)region return; } - [_locationManager startMonitoringForRegion:region]; + CLAuthorizationStatus status = [CLLocationManager authorizationStatus]; + if (status == kCLAuthorizationStatusAuthorizedWhenInUse) { + if (region.rangingEnabled) { + [_locationManager startRangingBeaconsInRegion:region]; + } + } else { + [_locationManager startMonitoringForRegion:region]; + } region.isMonitoring = YES; } @@ -452,8 +472,10 @@ - (NSString *)locationAuthorizationStatusString:(CLAuthorizationStatus)status return @"Restricted"; case kCLAuthorizationStatusDenied: return @"Denied"; - case kCLAuthorizationStatusAuthorized: - return @"Authorized"; + case kCLAuthorizationStatusAuthorizedAlways: + return @"AuthorizedAlways"; + case kCLAuthorizationStatusAuthorizedWhenInUse: + return @"AuthorizedWhenInUse"; } return @""; } From ab42669cc7166f6faf5e104c8432ba8c9983d674 Mon Sep 17 00:00:00 2001 From: aYukoIzuhara Date: Thu, 5 Apr 2018 14:38:09 +0900 Subject: [PATCH 2/2] Maintenance isRanging flag --- iOS/ABFBeacon/ABFBeacon.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOS/ABFBeacon/ABFBeacon.m b/iOS/ABFBeacon/ABFBeacon.m index 77251a0..9d672ea 100644 --- a/iOS/ABFBeacon/ABFBeacon.m +++ b/iOS/ABFBeacon/ABFBeacon.m @@ -194,7 +194,7 @@ - (void)enableMonitoringForRegion:(ABFBeaconRegion *)region CLAuthorizationStatus status = [CLLocationManager authorizationStatus]; if (status == kCLAuthorizationStatusAuthorizedWhenInUse) { if (region.rangingEnabled) { - [_locationManager startRangingBeaconsInRegion:region]; + [self startRanging:region]; } } else { [_locationManager startMonitoringForRegion:region];