Skip to content

Commit

Permalink
Regression fix: Allow accessing current location while debugging (#179)
Browse files Browse the repository at this point in the history
Also, related localization tweak
  • Loading branch information
nighthawk authored May 31, 2022
1 parent 7661c7c commit 5001030
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Sources/TripKit/core/Loc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ public class Loc : NSObject {
return NSLocalizedString("Search Results", tableName: "Shared", bundle: .tripKit, comment: "")
}

public static var LocalizationPermissionsMissing: String {
return NSLocalizedString("Location services are required to use this feature. Please go to the Settings app > Privacy > Location Services, make sure they are turned on and authorise this app.", tableName: "Shared", bundle: .tripKit, comment: "Location iOS authorisation needed text")
}


// MARK: - Format

Expand Down
21 changes: 18 additions & 3 deletions Sources/TripKit/managers/TKLocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,32 @@ public extension TKLocationManager {

}

extension TKLocationManager.LocalizationError: LocalizedError {
public var errorDescription: String? {
switch self {
case .authorizationDenied:
return Loc.LocalizationPermissionsMissing
case .featureNotAvailable:
return nil
}
}
}


// TKPermissionManager overrides

extension TKLocationManager {

open override func featureIsAvailable() -> Bool {
if Bundle.main.infoDictionary?.keys.contains("NSLocationWhenInUseUsageDescription") == true {
return true
}

#if DEBUG
// Assume available, when running tests
return ProcessInfo().environment.keys.contains("XCTestSessionIdentifier")
#else
return Bundle.main.infoDictionary?.keys.contains("NSLocationWhenInUseUsageDescription") == true
return false
#endif
}

Expand Down Expand Up @@ -71,8 +87,7 @@ extension TKLocationManager {
}

open override func authorizationAlertText() -> String {
return NSLocalizedString("Location services are required to use this feature. Please go to the Settings app > Privacy > Location Services, make sure they are turned on and authorise this app.", tableName: "Shared", bundle: .tripKit, comment: "Location iOS authorisation needed text")
return Loc.LocalizationPermissionsMissing
}


}

0 comments on commit 5001030

Please sign in to comment.