Skip to content

Commit 5c8db2a

Browse files
authored
Merge pull request #269 from GiftAMeal/main
Precise location support for iOS 14.0+
2 parents 228a4b9 + 05afe56 commit 5c8db2a

File tree

9 files changed

+146
-3
lines changed

9 files changed

+146
-3
lines changed

Example Apps/iOS Example/Scenes/RootController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import SPPermissionsHealth
4343

4444
class RootController: SPTableViewController {
4545

46-
var availablePermissions: [SPPermissions.Permission] = [.camera, .photoLibrary, .notification, .microphone, .calendar, .contacts, .reminders, .speech, .locationWhenInUse, .locationAlways, .motion, .mediaLibrary, .bluetooth, /*.tracking,*/ .faceID, .siri, .health]
46+
var availablePermissions: [SPPermissions.Permission] = [.camera, .photoLibrary, .notification, .microphone, .calendar, .contacts, .reminders, .speech, .locationWhenInUse, .locationAlways, .locationWhenInUsePrecise, .locationAlwaysPrecise .motion, .mediaLibrary, .bluetooth, /*.tracking,*/ .faceID, .siri, .health]
4747

4848
var selectedPermissions: [SPPermissions.Permission] = []
4949

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ let package = Package(
226226
.define("SPPERMISSIONS_HEALTH"),
227227
.define("SPPERMISSIONS_SPM")
228228
]
229-
)
229+
),
230230
],
231231
swiftLanguageVersions: [.v5]
232232
)

SPPermissions.podspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,4 @@ Pod::Spec.new do |s|
165165
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "SPPERMISSIONS_HEALTH SPPERMISSIONS_COCOAPODS"
166166
}
167167
end
168-
169168
end

Sources/SPPermissions/Data/Images.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ enum Images {
5959
return UIImage.init(named: "Siri", in: bundle, compatibleWith: nil) ?? UIImage()
6060
case .health:
6161
return UIImage.init(named: "Health", in: bundle, compatibleWith: nil) ?? UIImage()
62+
case .locationWhenInUsePrecise:
63+
return UIImage.init(named: "Location", in: bundle, compatibleWith: nil) ?? UIImage()
64+
case .locationAlwaysPrecise:
65+
return UIImage.init(named: "Location", in: bundle, compatibleWith: nil) ?? UIImage()
6266
}
6367
}
6468

Sources/SPPermissions/Data/Text.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ enum Texts {
5959
return NSLocalizedString("permission siri name", bundle: bundle, comment: "")
6060
case .health:
6161
return NSLocalizedString("permission health name", bundle: bundle, comment: "")
62+
case .locationWhenInUsePrecise:
63+
return NSLocalizedString("permission precise location when in use name", bundle: bundle, comment: "")
64+
case .locationAlwaysPrecise:
65+
return NSLocalizedString("permission precise location always name", bundle: bundle, comment: "")
6266
}
6367
}
6468

@@ -98,6 +102,10 @@ enum Texts {
98102
return NSLocalizedString("permission siri description", bundle: bundle, comment: "")
99103
case .health:
100104
return NSLocalizedString("permission health description", bundle: bundle, comment: "")
105+
case .locationWhenInUsePrecise:
106+
return NSLocalizedString("permission precise location when in use description", bundle: bundle, comment: "")
107+
case .locationAlwaysPrecise:
108+
return NSLocalizedString("permission precise location always description", bundle: bundle, comment: "")
101109
}
102110
}
103111

Sources/SPPermissions/Interface/Shared/SPPermissionsDrawIconView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public class SPPermissionsDrawIconView: UIView {
8282
case .faceID, .siri, .health:
8383
// Not implemented old style icons.
8484
break
85+
case .locationWhenInUsePrecise:
86+
DrawService.drawLocations(frame: rect, resizing: .aspectFit, color: tintColor)
87+
case .locationAlwaysPrecise:
88+
DrawService.drawLocations(frame: rect, resizing: .aspectFit, color: tintColor)
8589
case .none:
8690
break
8791
}

Sources/SPPermissions/SPPermissions.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ public enum SPPermissions {
205205
case faceID = 15
206206
case siri = 16
207207
case health = 17
208+
case locationWhenInUsePrecise = 18
209+
case locationAlwaysPrecise = 19
208210

209211
public var name: String {
210212
switch self {
@@ -242,6 +244,10 @@ public enum SPPermissions {
242244
return "Siri"
243245
case .health:
244246
return "Health"
247+
case .locationWhenInUsePrecise:
248+
return "Precise Location When Use "
249+
case .locationAlwaysPrecise:
250+
return "Precise Location Always"
245251
}
246252
}
247253
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2020 Ivan Vorobei ([email protected])
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
// SOFTWARE.
21+
22+
#if SPPERMISSIONS_SPM
23+
import SPPermissions
24+
#endif
25+
26+
#if os(iOS) && SPPERMISSIONS_LOCATION_ALWAYS
27+
28+
import Foundation
29+
import MapKit
30+
31+
public extension SPPermissions.Permission {
32+
33+
static var locationAlwaysPrecise: SPLocationAlwaysPrecisePermission {
34+
return SPLocationAlwaysPrecisePermission()
35+
}
36+
}
37+
38+
public class SPLocationAlwaysPrecisePermission: SPLocationAlwaysPermission {
39+
40+
public override var status: SPPermissions.PermissionStatus {
41+
let alwaysAuthorizationStatus = SPLocationAlwaysPermission().status
42+
43+
let hasPrecision: Bool = {
44+
#if os(iOS)
45+
if #available(iOS 14.0, *), CLLocationManager().accuracyAuthorization != .fullAccuracy {
46+
return false
47+
}
48+
#endif
49+
return true
50+
}()
51+
52+
switch alwaysAuthorizationStatus {
53+
#if os(iOS)
54+
case .authorized: return hasPrecision ? .authorized : .denied
55+
#endif
56+
default: return alwaysAuthorizationStatus
57+
}
58+
}
59+
}
60+
61+
#endif
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2020 Ivan Vorobei ([email protected])
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
// SOFTWARE.
21+
22+
#if SPPERMISSIONS_SPM
23+
import SPPermissions
24+
#endif
25+
26+
#if SPPERMISSIONS_LOCATION_WHENINUSE
27+
28+
import Foundation
29+
import MapKit
30+
31+
public extension SPPermissions.Permission {
32+
33+
static var locationWhenInUsePrecise: SPLocationWhenInUsePrecisePermission {
34+
return SPLocationWhenInUsePrecisePermission ()
35+
}
36+
}
37+
38+
public class SPLocationWhenInUsePrecisePermission: SPLocationWhenInUsePermission {
39+
40+
public override var status: SPPermissions.PermissionStatus {
41+
let whenInUseAuthorizationStatus = SPLocationWhenInUsePermission().status
42+
43+
let hasPrecision: Bool = {
44+
#if os(iOS)
45+
if #available(iOS 14.0, *), CLLocationManager().accuracyAuthorization != .fullAccuracy {
46+
return false
47+
}
48+
#endif
49+
return true
50+
}()
51+
52+
switch whenInUseAuthorizationStatus {
53+
#if os(iOS)
54+
case .authorized: return hasPrecision ? .authorized : .denied
55+
#endif
56+
default: return whenInUseAuthorizationStatus
57+
}
58+
}
59+
}
60+
61+
#endif

0 commit comments

Comments
 (0)