Skip to content

Commit

Permalink
Merge location permissions to one permission with access.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed Oct 2, 2023
1 parent a548063 commit c476309
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 163 deletions.
32 changes: 5 additions & 27 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ let package = Package(
targets: ["SpeechRecognizerPermission"]
),
.library(
name: "LocationWhenInUsePermission",
targets: ["LocationWhenInUsePermission"]
),
.library(
name: "LocationAlwaysPermission",
targets: ["LocationAlwaysPermission"]
name: "LocationPermission",
targets: ["LocationPermission"]
),
.library(
name: "MotionPermission",
Expand Down Expand Up @@ -91,12 +87,6 @@ let package = Package(
.define("PERMISSIONSKIT_SPM")
]
),
.target(
name: "LocationExtension",
swiftSettings: [
.define("PERMISSIONSKIT_SPM")
]
),
.target(
name: "CameraPermission",
dependencies: [.target(name: "PermissionsKit")],
Expand Down Expand Up @@ -162,24 +152,12 @@ let package = Package(
]
),
.target(
name: "LocationWhenInUsePermission",
dependencies: [
.target(name: "PermissionsKit"),
.target(name: "LocationExtension")
],
swiftSettings: [
.define("PERMISSIONSKIT_LOCATION_WHENINUSE"),
.define("PERMISSIONSKIT_SPM")
]
),
.target(
name: "LocationAlwaysPermission",
name: "LocationPermission",
dependencies: [
.target(name: "PermissionsKit"),
.target(name: "LocationExtension")
.target(name: "PermissionsKit")
],
swiftSettings: [
.define("PERMISSIONSKIT_LOCATION_ALWAYS"),
.define("PERMISSIONSKIT_LOCATION"),
.define("PERMISSIONSKIT_SPM")
]
),
Expand Down
22 changes: 4 additions & 18 deletions PermissionsKit.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "PermissionsKit"
s.version = "9.2.2"
s.version = "10.0.0"
s.summary = "Ask permissions with ready-use interface. You can check status permission and if it has been requested before. Support SwiftUI."
s.homepage = "https://github.com/sparrowcode/PermissionsKit"
s.source = { :git => "https://github.com/sparrowcode/PermissionsKit.git", :tag => s.version }
Expand Down Expand Up @@ -92,26 +92,12 @@ Pod::Spec.new do |s|
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "PERMISSIONSKIT_SPEECH PERMISSIONSKIT_COCOAPODS"
}
end

s.subspec 'LocationExtension' do |subspec|
subspec.source_files = "Sources/LocationExtension/**/*.swift"
end

s.subspec 'LocationWhenInUsePermission' do |subspec|
subspec.dependency 'PermissionsKit/Core'
subspec.dependency 'PermissionsKit/LocationExtension'
subspec.source_files = "Sources/LocationWhenInUsePermission/**/*.swift"
subspec.pod_target_xcconfig = {
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "PERMISSIONSKIT_LOCATION_WHENINUSE PERMISSIONSKIT_COCOAPODS"
}
end

s.subspec 'LocationAlwaysPermission' do |subspec|
s.subspec 'LocationPermission' do |subspec|
subspec.dependency 'PermissionsKit/Core'
subspec.dependency 'PermissionsKit/LocationExtension'
subspec.source_files = "Sources/LocationAlwaysPermission/**/*.swift"
subspec.source_files = "Sources/LocationPermission/**/*.swift"
subspec.pod_target_xcconfig = {
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "PERMISSIONSKIT_LOCATION_ALWAYS PERMISSIONSKIT_COCOAPODS"
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "PERMISSIONSKIT_LOCATION PERMISSIONSKIT_COCOAPODS"
}
end

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ Universal API for request permission and get its statuses. Available `.authorize
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/contacts.png" width="38"> | Contacts | NSContactsUsageDescription |||
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/faceid.png" width="38"> | FaceID | NSFaceIDUsageDescription |||
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/health.png" width="38"> | Health | NSHealthUpdateUsageDescription, NSHealthShareUsageDescription |||
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/location.png" width="38"> | Location Always | NSLocationAlwaysAndWhenInUseUsageDescription |||
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/location.png" width="38"> | Location When In Use | NSLocationWhenInUseUsageDescription |||
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/location.png" width="38"> | Location | NSLocationAlwaysAndWhenInUseUsageDescription NSLocationWhenInUseUsageDescription |||
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/music.png" width="38"> | Media Library | NSAppleMusicUsageDescription |||
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/microphone.png" width="38"> | Microphone | NSMicrophoneUsageDescription |||
| <img src="https://cdn.sparrowcode.io/github/permissionskit/icons/motion.png" width="38"> | Motion | NSMotionUsageDescription |||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@

#if PERMISSIONSKIT_SPM
import PermissionsKit
import LocationExtension
#endif

#if os(iOS) && PERMISSIONSKIT_LOCATION_ALWAYS
#if os(iOS) && PERMISSIONSKIT_LOCATION
import Foundation
import MapKit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@

#if PERMISSIONSKIT_SPM
import PermissionsKit
import LocationExtension
#endif

#if PERMISSIONSKIT_LOCATION_WHENINUSE
#if PERMISSIONSKIT_LOCATION
import Foundation
import MapKit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,43 @@

#if PERMISSIONSKIT_SPM
import PermissionsKit
import LocationExtension
#endif

#if os(iOS) && PERMISSIONSKIT_LOCATION_ALWAYS
#if os(iOS) && PERMISSIONSKIT_LOCATION
import Foundation
import MapKit
import EventKit

public extension Permission {

static var locationAlways: LocationAlwaysPermission {
return LocationAlwaysPermission()
static func location(access: LocationAccess) -> LocationPermission {
LocationPermission(kind: .location(access: access))
}
}

public class LocationAlwaysPermission: Permission {
public class LocationPermission: Permission {

private var _kind: Permission.Kind

open override var kind: Permission.Kind { .locationAlways }
open var usageDescriptionKey: String? { "NSLocationAlwaysAndWhenInUseUsageDescription" }
// MARK: - Init

init(kind: Permission.Kind) {
self._kind = kind
}

open override var kind: Permission.Kind { self._kind }
open var usageDescriptionKey: String? {
switch _kind {
case .location(let access):
switch access {
case .whenInUse:
return "NSLocationWhenInUseUsageDescription"
case .always:
return "NSLocationAlwaysAndWhenInUseUsageDescription"
}
default:
fatalError()
}
}

public override var status: Permission.Status {
let authorizationStatus: CLAuthorizationStatus = {
Expand Down Expand Up @@ -77,12 +96,28 @@ public class LocationAlwaysPermission: Permission {
}

public override func request(completion: @escaping () -> Void) {
LocationAlwaysHandler.shared = LocationAlwaysHandler()
LocationAlwaysHandler.shared?.requestPermission() {
DispatchQueue.main.async {
completion()
LocationAlwaysHandler.shared = nil
switch _kind {
case .location(let access):
switch access {
case .whenInUse:
LocationWhenInUseHandler.shared = LocationWhenInUseHandler()
LocationWhenInUseHandler.shared?.requestPermission() {
DispatchQueue.main.async {
completion()
LocationWhenInUseHandler.shared = nil
}
}
case .always:
LocationAlwaysHandler.shared = LocationAlwaysHandler()
LocationAlwaysHandler.shared?.requestPermission() {
DispatchQueue.main.async {
completion()
LocationAlwaysHandler.shared = nil
}
}
}
default:
fatalError()
}
}
}
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions Sources/PermissionsKit/Data/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ enum Texts {
return NSLocalizedString("permission bluetooth name", bundle: bundle, comment: "")
case .notification:
return NSLocalizedString("permission notification name", bundle: bundle, comment: "")
case .locationWhenInUse:
case .location(access: .whenInUse):
return NSLocalizedString("permission location when in use name", bundle: bundle, comment: "")
case .locationAlways:
case .location(access: .always):
return NSLocalizedString("permission location always name", bundle: bundle, comment: "")
case .tracking:
return NSLocalizedString("permission tracking name", bundle: bundle, comment: "")
Expand Down
20 changes: 13 additions & 7 deletions Sources/PermissionsKit/Permission.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ open class Permission {
case contacts
case reminders
case speech
// Upgrade location as calendar style
case locationWhenInUse
case locationAlways
case location(access: LocationAccess)
case motion
case mediaLibrary
case bluetooth
Expand All @@ -128,16 +126,20 @@ open class Permission {
return "Photo Library"
case .microphone:
return "Microphone"
case .calendar(access: .write), .calendar(access: .full):
case .calendar(access: .write):
return "Calendar Only Write"
case .calendar(access: .full):
return "Calendar"
case .contacts:
return "Contacts"
case .reminders:
return "Reminders"
case .speech:
return "Speech"
case .locationAlways:
case .location(access: .always):
return "Location Always"
case .location(access: .whenInUse):
return "Location When Use"
case .motion:
return "Motion"
case .mediaLibrary:
Expand All @@ -146,8 +148,6 @@ open class Permission {
return "Bluetooth"
case .notification:
return "Notification"
case .locationWhenInUse:
return "Location When Use"
case .tracking:
return "Tracking"
case .faceID:
Expand All @@ -165,4 +165,10 @@ open class Permission {
case full
case write
}

public enum LocationAccess {

case whenInUse
case always
}
}

0 comments on commit c476309

Please sign in to comment.