Skip to content
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

Fix incorrect nonDetermined status handling causing unauthorized error for one shot requests #316

Merged
merged 3 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ SwiftLocation.gpsLocation().then {
}
```

**Remember**: Before using SwiftLocation you should set the appropriate keys in your Info.plist (`NSLocationAlwaysAndWhenInUseUsageDescription` or `NSLocationWhenInUseUsageDescription` and `NSLocationTemporaryUsageDescriptionDictionary` if you are using reduced location in iOS 14+).

If you need more customization you can fine-tune your request by configuring each of the available parameters. This is a more complex example:

```swift
Expand Down Expand Up @@ -438,9 +440,9 @@ func application(_ application: UIApplication, didFinishLaunchingWithOptions lau

If you want to disable automatic requests save you can set the `SwiftLocation.automaticRequestSave = false`.

<a name="installation"/>
<a name="precisereducedlocation"/>

- [Precise & Reduced Location in iOS 14+](#precisereducedlocation)
## Precise & Reduced Location in iOS 14+

Location data are very sensitive; since iOS 14 Apple introduced a further layer of privacy to Core Location Manager: **users can choose whether to give precise or approximate location access**.
Since 5.0.1 SwiftLocation supports this options and it's transparent to old iOS versions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ extension CLAuthorizationStatus: CustomStringConvertible {
return false
}
}

internal var isRejected: Bool {
switch self {
case .denied, .restricted:
return true
default:
return false
}
}

public var description: String {
switch self {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftLocation/SwiftLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ public class LocationManager: LocationManagerDelegate, CustomStringConvertible {
}

private func failWeakAuthorizationRequests() {
guard authorizationStatus.isAuthorized == false else {
guard authorizationStatus.isRejected == true else {
// If we have already the authorization even request with `avoidRequestAuthorization = true`
// may receive notifications of locations.
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class GPSController: UIViewController, UITableViewDelegate, UITableViewDataSourc
let request = SwiftLocation.gpsLocationWith(serviceOptions)

serviceOptions = GPSLocationOptions()
serviceOptions.avoidRequestAuthorization = true
reloadData()

AppDelegate.attachSubscribersToGPS([request])
Expand Down