Skip to content

Commit c476309

Browse files
committed
Merge location permissions to one permission with access.
1 parent a548063 commit c476309

File tree

10 files changed

+76
-163
lines changed

10 files changed

+76
-163
lines changed

Package.swift

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ let package = Package(
4444
targets: ["SpeechRecognizerPermission"]
4545
),
4646
.library(
47-
name: "LocationWhenInUsePermission",
48-
targets: ["LocationWhenInUsePermission"]
49-
),
50-
.library(
51-
name: "LocationAlwaysPermission",
52-
targets: ["LocationAlwaysPermission"]
47+
name: "LocationPermission",
48+
targets: ["LocationPermission"]
5349
),
5450
.library(
5551
name: "MotionPermission",
@@ -91,12 +87,6 @@ let package = Package(
9187
.define("PERMISSIONSKIT_SPM")
9288
]
9389
),
94-
.target(
95-
name: "LocationExtension",
96-
swiftSettings: [
97-
.define("PERMISSIONSKIT_SPM")
98-
]
99-
),
10090
.target(
10191
name: "CameraPermission",
10292
dependencies: [.target(name: "PermissionsKit")],
@@ -162,24 +152,12 @@ let package = Package(
162152
]
163153
),
164154
.target(
165-
name: "LocationWhenInUsePermission",
166-
dependencies: [
167-
.target(name: "PermissionsKit"),
168-
.target(name: "LocationExtension")
169-
],
170-
swiftSettings: [
171-
.define("PERMISSIONSKIT_LOCATION_WHENINUSE"),
172-
.define("PERMISSIONSKIT_SPM")
173-
]
174-
),
175-
.target(
176-
name: "LocationAlwaysPermission",
155+
name: "LocationPermission",
177156
dependencies: [
178-
.target(name: "PermissionsKit"),
179-
.target(name: "LocationExtension")
157+
.target(name: "PermissionsKit")
180158
],
181159
swiftSettings: [
182-
.define("PERMISSIONSKIT_LOCATION_ALWAYS"),
160+
.define("PERMISSIONSKIT_LOCATION"),
183161
.define("PERMISSIONSKIT_SPM")
184162
]
185163
),

PermissionsKit.podspec

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "PermissionsKit"
4-
s.version = "9.2.2"
4+
s.version = "10.0.0"
55
s.summary = "Ask permissions with ready-use interface. You can check status permission and if it has been requested before. Support SwiftUI."
66
s.homepage = "https://github.com/sparrowcode/PermissionsKit"
77
s.source = { :git => "https://github.com/sparrowcode/PermissionsKit.git", :tag => s.version }
@@ -92,26 +92,12 @@ Pod::Spec.new do |s|
9292
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "PERMISSIONSKIT_SPEECH PERMISSIONSKIT_COCOAPODS"
9393
}
9494
end
95-
96-
s.subspec 'LocationExtension' do |subspec|
97-
subspec.source_files = "Sources/LocationExtension/**/*.swift"
98-
end
9995

100-
s.subspec 'LocationWhenInUsePermission' do |subspec|
101-
subspec.dependency 'PermissionsKit/Core'
102-
subspec.dependency 'PermissionsKit/LocationExtension'
103-
subspec.source_files = "Sources/LocationWhenInUsePermission/**/*.swift"
104-
subspec.pod_target_xcconfig = {
105-
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "PERMISSIONSKIT_LOCATION_WHENINUSE PERMISSIONSKIT_COCOAPODS"
106-
}
107-
end
108-
109-
s.subspec 'LocationAlwaysPermission' do |subspec|
96+
s.subspec 'LocationPermission' do |subspec|
11097
subspec.dependency 'PermissionsKit/Core'
111-
subspec.dependency 'PermissionsKit/LocationExtension'
112-
subspec.source_files = "Sources/LocationAlwaysPermission/**/*.swift"
98+
subspec.source_files = "Sources/LocationPermission/**/*.swift"
11399
subspec.pod_target_xcconfig = {
114-
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "PERMISSIONSKIT_LOCATION_ALWAYS PERMISSIONSKIT_COCOAPODS"
100+
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "PERMISSIONSKIT_LOCATION PERMISSIONSKIT_COCOAPODS"
115101
}
116102
end
117103

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ Universal API for request permission and get its statuses. Available `.authorize
5858
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/contacts.png" width="38"> | Contacts | NSContactsUsageDescription |||
5959
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/faceid.png" width="38"> | FaceID | NSFaceIDUsageDescription |||
6060
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/health.png" width="38"> | Health | NSHealthUpdateUsageDescription, NSHealthShareUsageDescription |||
61-
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/location.png" width="38"> | Location Always | NSLocationAlwaysAndWhenInUseUsageDescription |||
62-
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/location.png" width="38"> | Location When In Use | NSLocationWhenInUseUsageDescription |||
61+
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/location.png" width="38"> | Location | NSLocationAlwaysAndWhenInUseUsageDescription NSLocationWhenInUseUsageDescription |||
6362
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/music.png" width="38"> | Media Library | NSAppleMusicUsageDescription |||
6463
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/microphone.png" width="38"> | Microphone | NSMicrophoneUsageDescription |||
6564
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/motion.png" width="38"> | Motion | NSMotionUsageDescription |||

Sources/LocationAlwaysPermission/LocationAlwaysHandler.swift renamed to Sources/LocationPermission/Handlers/LocationAlwaysHandler.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121

2222
#if PERMISSIONSKIT_SPM
2323
import PermissionsKit
24-
import LocationExtension
2524
#endif
2625

27-
#if os(iOS) && PERMISSIONSKIT_LOCATION_ALWAYS
26+
#if os(iOS) && PERMISSIONSKIT_LOCATION
2827
import Foundation
2928
import MapKit
3029

Sources/LocationWhenInUsePermission/LocationWhenInUseHandler.swift renamed to Sources/LocationPermission/Handlers/LocationWhenInUseHandler.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121

2222
#if PERMISSIONSKIT_SPM
2323
import PermissionsKit
24-
import LocationExtension
2524
#endif
2625

27-
#if PERMISSIONSKIT_LOCATION_WHENINUSE
26+
#if PERMISSIONSKIT_LOCATION
2827
import Foundation
2928
import MapKit
3029

Sources/LocationAlwaysPermission/LocationAlwaysPermission.swift renamed to Sources/LocationPermission/LocationPermission.swift

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,43 @@
2121

2222
#if PERMISSIONSKIT_SPM
2323
import PermissionsKit
24-
import LocationExtension
2524
#endif
2625

27-
#if os(iOS) && PERMISSIONSKIT_LOCATION_ALWAYS
26+
#if os(iOS) && PERMISSIONSKIT_LOCATION
2827
import Foundation
29-
import MapKit
28+
import EventKit
3029

3130
public extension Permission {
32-
33-
static var locationAlways: LocationAlwaysPermission {
34-
return LocationAlwaysPermission()
31+
32+
static func location(access: LocationAccess) -> LocationPermission {
33+
LocationPermission(kind: .location(access: access))
3534
}
3635
}
3736

38-
public class LocationAlwaysPermission: Permission {
37+
public class LocationPermission: Permission {
38+
39+
private var _kind: Permission.Kind
3940

40-
open override var kind: Permission.Kind { .locationAlways }
41-
open var usageDescriptionKey: String? { "NSLocationAlwaysAndWhenInUseUsageDescription" }
41+
// MARK: - Init
42+
43+
init(kind: Permission.Kind) {
44+
self._kind = kind
45+
}
46+
47+
open override var kind: Permission.Kind { self._kind }
48+
open var usageDescriptionKey: String? {
49+
switch _kind {
50+
case .location(let access):
51+
switch access {
52+
case .whenInUse:
53+
return "NSLocationWhenInUseUsageDescription"
54+
case .always:
55+
return "NSLocationAlwaysAndWhenInUseUsageDescription"
56+
}
57+
default:
58+
fatalError()
59+
}
60+
}
4261

4362
public override var status: Permission.Status {
4463
let authorizationStatus: CLAuthorizationStatus = {
@@ -77,12 +96,28 @@ public class LocationAlwaysPermission: Permission {
7796
}
7897

7998
public override func request(completion: @escaping () -> Void) {
80-
LocationAlwaysHandler.shared = LocationAlwaysHandler()
81-
LocationAlwaysHandler.shared?.requestPermission() {
82-
DispatchQueue.main.async {
83-
completion()
84-
LocationAlwaysHandler.shared = nil
99+
switch _kind {
100+
case .location(let access):
101+
switch access {
102+
case .whenInUse:
103+
LocationWhenInUseHandler.shared = LocationWhenInUseHandler()
104+
LocationWhenInUseHandler.shared?.requestPermission() {
105+
DispatchQueue.main.async {
106+
completion()
107+
LocationWhenInUseHandler.shared = nil
108+
}
109+
}
110+
case .always:
111+
LocationAlwaysHandler.shared = LocationAlwaysHandler()
112+
LocationAlwaysHandler.shared?.requestPermission() {
113+
DispatchQueue.main.async {
114+
completion()
115+
LocationAlwaysHandler.shared = nil
116+
}
117+
}
85118
}
119+
default:
120+
fatalError()
86121
}
87122
}
88123
}

Sources/LocationWhenInUsePermission/LocationWhenInUsePermission.swift

Lines changed: 0 additions & 89 deletions
This file was deleted.

Sources/PermissionsKit/Data/Text.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ enum Texts {
4747
return NSLocalizedString("permission bluetooth name", bundle: bundle, comment: "")
4848
case .notification:
4949
return NSLocalizedString("permission notification name", bundle: bundle, comment: "")
50-
case .locationWhenInUse:
50+
case .location(access: .whenInUse):
5151
return NSLocalizedString("permission location when in use name", bundle: bundle, comment: "")
52-
case .locationAlways:
52+
case .location(access: .always):
5353
return NSLocalizedString("permission location always name", bundle: bundle, comment: "")
5454
case .tracking:
5555
return NSLocalizedString("permission tracking name", bundle: bundle, comment: "")

Sources/PermissionsKit/Permission.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ open class Permission {
109109
case contacts
110110
case reminders
111111
case speech
112-
// Upgrade location as calendar style
113-
case locationWhenInUse
114-
case locationAlways
112+
case location(access: LocationAccess)
115113
case motion
116114
case mediaLibrary
117115
case bluetooth
@@ -128,16 +126,20 @@ open class Permission {
128126
return "Photo Library"
129127
case .microphone:
130128
return "Microphone"
131-
case .calendar(access: .write), .calendar(access: .full):
129+
case .calendar(access: .write):
130+
return "Calendar Only Write"
131+
case .calendar(access: .full):
132132
return "Calendar"
133133
case .contacts:
134134
return "Contacts"
135135
case .reminders:
136136
return "Reminders"
137137
case .speech:
138138
return "Speech"
139-
case .locationAlways:
139+
case .location(access: .always):
140140
return "Location Always"
141+
case .location(access: .whenInUse):
142+
return "Location When Use"
141143
case .motion:
142144
return "Motion"
143145
case .mediaLibrary:
@@ -146,8 +148,6 @@ open class Permission {
146148
return "Bluetooth"
147149
case .notification:
148150
return "Notification"
149-
case .locationWhenInUse:
150-
return "Location When Use"
151151
case .tracking:
152152
return "Tracking"
153153
case .faceID:
@@ -165,4 +165,10 @@ open class Permission {
165165
case full
166166
case write
167167
}
168+
169+
public enum LocationAccess {
170+
171+
case whenInUse
172+
case always
173+
}
168174
}

0 commit comments

Comments
 (0)