-
-
Notifications
You must be signed in to change notification settings - Fork 817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Location full accuracy (issue #489) #503
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d3073bf
Add LocationFullAccuracy for new iOS14 permission
adapptor-kurt b309a13
Add to examples
adapptor-kurt b30f43d
Fold the purposeKey into the Rational instead of adding a new function
adapptor-kurt b645aaf
Merge remote-tracking branch 'community/master' into location-full-ac…
adapptor-kurt 7bfb44a
Restore original type of request to ensure backwards compatibility. …
adapptor-kurt c9b6de4
Remove incorrect and unnecessary test of authorizationStatus.
adapptor-kurt 568f153
Use full-accuracy as default purpose key. Make options a union based…
adapptor-kurt 13bceb1
Merge remote-tracking branch 'community/master' into location-full-ac…
adapptor-kurt File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'json' | ||
package = JSON.parse(File.read('../package.json')) | ||
|
||
Pod::Spec.new do |s| | ||
s.name = "Permission-LocationFullAccuracy" | ||
s.dependency "RNPermissions" | ||
|
||
s.version = package["version"] | ||
s.license = package["license"] | ||
s.summary = package["description"] | ||
s.authors = package["author"] | ||
s.homepage = package["homepage"] | ||
|
||
s.platform = :ios, "9.0" | ||
s.ios.deployment_target = "9.0" | ||
s.tvos.deployment_target = "11.0" | ||
s.requires_arc = true | ||
|
||
s.source = { :git => package["repository"]["url"], :tag => s.version } | ||
s.source_files = "LocationFullAccuracy/*.{h,m}" | ||
end |
5 changes: 5 additions & 0 deletions
5
ios/LocationFullAccuracy/RNPermissionHandlerLocationFullAccuracy.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#import "RNPermissions.h" | ||
|
||
@interface RNPermissionHandlerLocationFullAccuracy : NSObject<RNPermissionHandler> | ||
|
||
@end |
82 changes: 82 additions & 0 deletions
82
ios/LocationFullAccuracy/RNPermissionHandlerLocationFullAccuracy.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#import "RNPermissionHandlerLocationFullAccuracy.h" | ||
|
||
@import CoreLocation; | ||
@import UIKit; | ||
|
||
NSErrorDomain const RNPermissionHandlerLocationFullAccuracyDomain = @"RNPermissionHandlerLocationFullAccuracy"; | ||
NS_ENUM(NSInteger) { | ||
RNPermissionHandlerLocationFullAccuracyNoPurposeKey = 1, | ||
}; | ||
|
||
@interface RNPermissionHandlerLocationFullAccuracy() | ||
|
||
@end | ||
|
||
@implementation RNPermissionHandlerLocationFullAccuracy | ||
|
||
+ (NSArray<NSString *> * _Nonnull)usageDescriptionKeys { | ||
return @[ | ||
@"NSLocationTemporaryUsageDescriptionDictionary" | ||
]; | ||
} | ||
|
||
+ (NSString * _Nonnull)handlerUniqueId { | ||
return @"ios.permission.LOCATION_FULL_ACCURACY"; | ||
} | ||
|
||
+ (RNPermissionStatus)getAccuracyStatus:(CLLocationManager *)locationManager API_AVAILABLE(ios(14.0)) { | ||
switch (locationManager.accuracyAuthorization) { | ||
case CLAccuracyAuthorizationFullAccuracy: | ||
return RNPermissionStatusAuthorized; | ||
case CLAccuracyAuthorizationReducedAccuracy: | ||
default: | ||
return RNPermissionStatusNotDetermined; | ||
} | ||
} | ||
|
||
- (void)checkWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve | ||
rejecter:(void (__unused ^ _Nonnull)(NSError * _Nonnull))reject { | ||
if (!CLLocationManager.locationServicesEnabled) { | ||
return resolve(RNPermissionStatusNotAvailable); | ||
} | ||
|
||
if (@available(iOS 14.0, *)) { | ||
CLLocationManager *locationManager = [CLLocationManager new]; | ||
return resolve([RNPermissionHandlerLocationFullAccuracy getAccuracyStatus:locationManager]); | ||
} else { | ||
return resolve(RNPermissionStatusAuthorized); | ||
} | ||
} | ||
|
||
- (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve | ||
rejecter:(void (^ _Nonnull)(NSError * _Nonnull))reject | ||
options:(NSDictionary *_Nullable)options { | ||
if (!CLLocationManager.locationServicesEnabled) { | ||
return resolve(RNPermissionStatusNotAvailable); | ||
} | ||
|
||
if (@available(iOS 14.0, *)) { | ||
CLLocationManager *locationManager = [CLLocationManager new]; | ||
NSString *purposeKey = [options objectForKey:@"temporaryPurposeKey"]; | ||
|
||
if (!purposeKey) { | ||
purposeKey = @"full-accuracy"; | ||
} | ||
|
||
[locationManager requestTemporaryFullAccuracyAuthorizationWithPurposeKey:purposeKey | ||
completion:^(NSError * _Nullable error) { | ||
RNPermissionStatus status = [RNPermissionHandlerLocationFullAccuracy getAccuracyStatus:locationManager]; | ||
|
||
// Ignore errors due to full accuracy already being authorized | ||
if (error && (error.code != kCLErrorPromptDeclined || status != RNPermissionStatusAuthorized)) { | ||
return reject(error); | ||
} else { | ||
return resolve(status); | ||
} | ||
}]; | ||
} else { | ||
return resolve(RNPermissionStatusAuthorized); | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it
(error && error.code != kCLErrorPromptDeclined) || status != RNPermissionStatusAuthorized
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, a failure to get authorisation should still resolve the promise successfully.
What's happening here is that requestTemporaryFullAccuracyAuthorizationWithPurposeKey will error with kCLErrorPromptDeclined when permission is already granted, causing it not to show a prompt to the user. When we see this error, and can confirm that authorisation is granted, the call is treated as a success instead.