Skip to content

Commit

Permalink
Add permissionStatus field to the location event
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Yeshkunov committed Apr 19, 2022
1 parent eb9b779 commit 9487c33
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void mme_linkCLLocationManagerCategory();

- (CLAuthorizationStatus)mme_authorizationStatus;
- (NSString *)mme_authorizationStatusString;
- (NSString *)mme_permissionStatusString;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
- (CLAccuracyAuthorization)mme_accuracyStatus API_AVAILABLE(ios(14.0), macos(11.0), watchos(7.0), tvos(14.0));
Expand Down
19 changes: 19 additions & 0 deletions Sources/MapboxMobileEvents/CLLocationManager+MMEMobileEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ - (NSString *)mme_authorizationStatusString {
return statusString;
}

- (NSString *)mme_permissionStatusString {
// this method should be called when generation a location event, so the authorization should be granted
CLAuthorizationStatus status = [self mme_authorizationStatus];
NSString *statusString;

switch (status) {
case kCLAuthorizationStatusAuthorizedAlways:
statusString = MMEEventAuthStatusAllowAlways;
break;
case kCLAuthorizationStatusAuthorizedWhenInUse:
statusString = MMEEventAuthStatusAllowWhenInUse;
break;
default:
statusString = @"";
break;
}
return statusString;
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
- (CLAccuracyAuthorization)mme_accuracyStatus {
return [self accuracyAuthorization];
Expand Down
3 changes: 3 additions & 0 deletions Sources/MapboxMobileEvents/MMEConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
NSString * const MMEEventKeySpeedAccuracy = @"speedAccuracy";
NSString * const MMEEventKeyCourseAccuracy = @"courseAccuracy";
NSString * const MMEEventKeyVerticalAccuracy = @"verticalAccuracy";
NSString * const MMEEventKeyPermissionStatus = @"permissionStatus";
NSString * const MMEEventKeyFloor = @"floor";
NSString * const MMEEventHorizontalAccuracy = @"horizontalAccuracy";
NSString * const MMEEventKeyLocalDebugDescription = @"debug.description";
Expand Down Expand Up @@ -121,6 +122,8 @@
NSString * const MMEEventStatusAuthorizedAlways = @"always";
NSString * const MMEEventStatusAuthorizedWhenInUse = @"whenInUse";
NSString * const MMEEventUnknown = @"unknown";
NSString * const MMEEventAuthStatusAllowWhenInUse = @"AllowWhenInUse";
NSString * const MMEEventAuthStatusAllowAlways = @"AllowAlways";

NSString * const MMEAccuracyAuthorizationFull = @"full";
NSString * const MMEAccuracyAuthorizationReduced = @"reduced";
Expand Down
6 changes: 6 additions & 0 deletions Sources/MapboxMobileEvents/MMEEventsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,12 @@ - (void)locationManager:(MMELocationManager *)locationManager didUpdateLocations
MMEEventKeyCourse: @([location mme_roundedCourse])
}];

if (locationManager != nil) {
[eventAttributes addEntriesFromDictionary:@{
MMEEventKeyPermissionStatus: locationManager.locationPermissionStatusString,
}];
}

NSString *digest = NSUserDefaults.mme_configuration.mme_configDigestValue;
if (digest) {
[eventAttributes addEntriesFromDictionary:@{
Expand Down
1 change: 1 addition & 0 deletions Sources/MapboxMobileEvents/MMELocationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- (void)startUpdatingLocation;
- (void)stopUpdatingLocation;
- (NSString *)locationAuthorizationString;
- (NSString *)locationPermissionStatusString;
- (CLAuthorizationStatus)locationAuthorization;

- (BOOL)isReducedAccuracy;
Expand Down
4 changes: 4 additions & 0 deletions Sources/MapboxMobileEvents/MMELocationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ - (NSString *)locationAuthorizationString {
return [self.locationManager mme_authorizationStatusString];
}

- (NSString *)locationPermissionStatusString {
return [self.locationManager mme_permissionStatusString];
}

- (CLAuthorizationStatus)locationAuthorization {
return [self.locationManager mme_authorizationStatus];
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/MapboxMobileEvents/include/MMEConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ extern NSString * const MMEEventKeyCourse;
extern NSString * const MMEEventKeySpeedAccuracy;
extern NSString * const MMEEventKeyCourseAccuracy;
extern NSString * const MMEEventKeyVerticalAccuracy;
extern NSString * const MMEEventKeyPermissionStatus;
extern NSString * const MMEEventKeyFloor;
extern NSString * const MMEEventKeyVendorId;
extern NSString * const MMEEventKeyModel;
Expand Down Expand Up @@ -135,6 +136,9 @@ extern NSString * const MMEEventStatusRestricted;
extern NSString * const MMEEventStatusNotDetermined;
extern NSString * const MMEEventStatusAuthorizedAlways;
extern NSString * const MMEEventStatusAuthorizedWhenInUse;
extern NSString * const MMEEventAuthStatusAllow;
extern NSString * const MMEEventAuthStatusAllowWhenInUse;
extern NSString * const MMEEventAuthStatusAllowAlways;
extern NSString * const MMEEventUnknown;
extern NSString * const MMEAccuracyAuthorizationFull;
extern NSString * const MMEAccuracyAuthorizationReduced;
Expand Down

0 comments on commit 9487c33

Please sign in to comment.