Removed precise library. Moved precise to location permissions. Updated Readme.

This commit is contained in:
Ivan Vorobei committed 2022-01-01 19:59:20 +03:00
1 parent ff226231b6
commit 9d9673ca5f
30 files changed
+110 -238

No files matched your search

+3 -2
View File
@@ -1,8 +1,9 @@
/Assets
# osX files
.DS_Store
.Trashes
# Swift Package Manager
.swiftpm
# User Interface
*UserInterfaceState.xcuserstate
@@ -43,7 +43,7 @@ import SPPermissionsHealth
class RootController: SPTableViewController {
var availablePermissions: [SPPermissions.Permission] = [.camera, .photoLibrary, .notification, .microphone, .calendar, .contacts, .reminders, .speech, .locationWhenInUse, .locationAlways, .locationWhenInUsePrecise, .locationAlwaysPrecise, .motion, .mediaLibrary, .bluetooth, /*.tracking,*/ .faceID, .siri, .health]
var availablePermissions: [SPPermissions.Permission] = [.camera, .photoLibrary, .notification, .microphone, .calendar, .contacts, .reminders, .speech, .locationWhenInUse, .locationAlways, .motion, .mediaLibrary, .bluetooth, /*.tracking,*/ .faceID, .siri, .health]
var selectedPermissions: [SPPermissions.Permission] = []
@@ -66,7 +66,7 @@ class RootController: SPTableViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Choose Style"
SPPermissions.Permission.locationWhenInUse.isPrecise
// Available styles: List, Dialog & Native.
let segmentedControl = UISegmentedControl(items: ["List", "Dialog", "Native"])
navigationItem.titleView = segmentedControl
+14 -2
View File
@@ -91,6 +91,12 @@ let package = Package(
.define("SPPERMISSIONS_SPM")
]
),
.target(
name: "SPPermissionsLocationExtension",
swiftSettings: [
.define("SPPERMISSIONS_SPM")
]
),
.target(
name: "SPPermissionsCamera",
dependencies: [.target(name: "SPPermissions")],
@@ -157,7 +163,10 @@ let package = Package(
),
.target(
name: "SPPermissionsLocationWhenInUse",
dependencies: [.target(name: "SPPermissions")],
dependencies: [
.target(name: "SPPermissions"),
.target(name: "SPPermissionsLocationExtension")
],
swiftSettings: [
.define("SPPERMISSIONS_LOCATION_WHENINUSE"),
.define("SPPERMISSIONS_SPM")
@@ -165,7 +174,10 @@ let package = Package(
),
.target(
name: "SPPermissionsLocationAlways",
dependencies: [.target(name: "SPPermissions")],
dependencies: [
.target(name: "SPPermissions"),
.target(name: "SPPermissionsLocationExtension")
],
swiftSettings: [
.define("SPPERMISSIONS_LOCATION_ALWAYS"),
.define("SPPERMISSIONS_SPM")
+13 -2
View File
@@ -38,6 +38,7 @@ Availalbe three ready-use interface - list, dialog & native. Supports iPad, dark
- [Imports](#imports)
- [Quick Start](#quick-start)
- [Status](#status)
- [Location](#location)
- [Request](#request)
- [List](#list)
- [Dialog](#dialog)
@@ -53,7 +54,7 @@ Availalbe three ready-use interface - list, dialog & native. Supports iPad, dark
## Installation
Ready to use on iOS 11+, and supports iOS, tvOS, and SwiftUI.
Ready to use on iOS 11+. Supports iOS, tvOS, and `SwiftUI`.
### Swift Package Manager
@@ -63,7 +64,7 @@ Once you have your Swift package set up, adding as a dependency is as easy as ad
```swift
dependencies: [
.package(url: "https://github.com/ivanvorobei/SPPermissions", .upToNextMajor(from: "7.0.1"))
.package(url: "https://github.com/ivanvorobei/SPPermissions", .upToNextMajor(from: "7.1.0"))
]
```
@@ -205,6 +206,16 @@ let authorized = SPPermissions.Permission.calendar.authorized
Also available are status for `denied` & `notDetermined`.
### Location
For location user can granted `precise` or not. For get state for it, call this:
```swift
if SPPermissions.Permission.locationWhenInUse.isPrecise { ... }
```
Same for `.locationAlways`.
## Request
`SPPermissions` has three presentation styles: `Dialog`, `List` and `Native`. Each interface has delegates and a data source. If you want see an example app, open `Example Apps/SPPermissions.xcodeproj`.
+7 -1
View File
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "SPPermissions"
s.version = "7.0.1"
s.version = "7.1.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/ivanvorobei/SPPermissions"
s.source = { :git => "https://github.com/ivanvorobei/SPPermissions.git", :tag => s.version }
@@ -93,9 +93,14 @@ Pod::Spec.new do |s|
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "SPPERMISSIONS_SPEECH SPPERMISSIONS_COCOAPODS"
}
end
s.subspec 'LocationExtension' do |subspec|
subspec.source_files = "Sources/SPPermissionsLocationExtension/**/*.swift"
end
s.subspec 'LocationWhenInUse' do |subspec|
subspec.dependency 'SPPermissions/Core'
subspec.dependency 'SPPermissions/LocationExtension'
subspec.source_files = "Sources/SPPermissionsLocationWhenInUse/**/*.swift"
subspec.pod_target_xcconfig = {
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "SPPERMISSIONS_LOCATION_WHENINUSE SPPERMISSIONS_COCOAPODS"
@@ -104,6 +109,7 @@ Pod::Spec.new do |s|
s.subspec 'LocationAlways' do |subspec|
subspec.dependency 'SPPermissions/Core'
subspec.dependency 'SPPermissions/LocationExtension'
subspec.source_files = "Sources/SPPermissionsLocationAlways/**/*.swift"
subspec.pod_target_xcconfig = {
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "SPPERMISSIONS_LOCATION_ALWAYS SPPERMISSIONS_COCOAPODS"
-4
View File
@@ -59,10 +59,6 @@ enum Images {
return UIImage.init(named: "Siri", in: bundle, compatibleWith: nil) ?? UIImage()
case .health:
return UIImage.init(named: "Health", in: bundle, compatibleWith: nil) ?? UIImage()
case .locationWhenInUsePrecise:
return UIImage.init(named: "Location", in: bundle, compatibleWith: nil) ?? UIImage()
case .locationAlwaysPrecise:
return UIImage.init(named: "Location", in: bundle, compatibleWith: nil) ?? UIImage()
}
}
-8
View File
@@ -59,10 +59,6 @@ enum Texts {
return NSLocalizedString("permission siri name", bundle: bundle, comment: "")
case .health:
return NSLocalizedString("permission health name", bundle: bundle, comment: "")
case .locationWhenInUsePrecise:
return NSLocalizedString("permission location precise when in use name", bundle: bundle, comment: "")
case .locationAlwaysPrecise:
return NSLocalizedString("permission location precise always name", bundle: bundle, comment: "")
}
}
@@ -102,10 +98,6 @@ enum Texts {
return NSLocalizedString("permission siri description", bundle: bundle, comment: "")
case .health:
return NSLocalizedString("permission health description", bundle: bundle, comment: "")
case .locationWhenInUsePrecise:
return NSLocalizedString("permission location precise when in use description", bundle: bundle, comment: "")
case .locationAlwaysPrecise:
return NSLocalizedString("permission location precise always description", bundle: bundle, comment: "")
}
}
@@ -82,10 +82,6 @@ public class SPPermissionsDrawIconView: UIView {
case .faceID, .siri, .health:
// Not implemented old style icons.
break
case .locationWhenInUsePrecise:
DrawService.drawLocations(frame: rect, resizing: .aspectFit, color: tintColor)
case .locationAlwaysPrecise:
DrawService.drawLocations(frame: rect, resizing: .aspectFit, color: tintColor)
case .none:
break
}
@@ -62,14 +62,6 @@
"permission location always description" = "السماح للوصول إلى موقعك";
"permission location precise when in use name" = "الموقع الدقيق عند الاستخدام";
"permission location precise always name" = "الموقع الدقيق دائمًا";
"permission location precise when in use description" = "اسمح بالوصول إلى موقعك الدقيق";
"permission location precise always description" = "اسمح بالوصول إلى موقعك الدقيق";
"permission tracking name" = "تتبع";
"permission tracking description" = "السماح بالوصول إلى البيانات المتعلقة بالتطبيق";
@@ -62,14 +62,6 @@
"permission location always description" = "Erlauben Sie den Zugriff auf Ihren Standort";
"permission location precise when in use name" = "Präzise Ortung bei Verwendung";
"permission location precise always name" = "Genaue Position immer";
"permission location precise when in use description" = "Zugriff auf Ihren genauen Standort zulassen";
"permission location precise always description" = "Zugriff auf Ihren genauen Standort zulassen";
"permission tracking name" = "Nachverfolgung";
"permission tracking description" = "Zugriff auf app-bezogene Daten zulassen";
@@ -62,14 +62,6 @@
"permission location always description" = "Allow to access your location";
"permission location precise when in use name" = "Precise Location When Use";
"permission location precise always name" = "Precise Location Always";
"permission location precise when in use description" = "Allow to access your precise location";
"permission location precise always description" = "Allow to access your precise location";
"permission tracking name" = "Tracking";
"permission tracking description" = "Allow to access app-related data";
@@ -63,14 +63,6 @@
"permission location always description" = "Permitir el acceso a su ubicación
";
"permission location precise when in use name" = "Ubicación precisa cuando se usa";
"permission location precise always name" = "Ubicación precisa siempre";
"permission location precise when in use description" = "Permitir el acceso a su ubicación precisa";
"permission location precise always description" = "Permitir el acceso a su ubicación precisa";
"permission tracking name" = "Seguimiento de";
"permission tracking description" = "Permitir el acceso a los datos relacionados con la aplicación";
@@ -62,14 +62,6 @@
"permission location always description" = "Autorisez l'accès à votre emplacement";
"permission location precise when in use name" = "Localisation précise lors de l'utilisation";
"permission location precise always name" = "Localisation précise toujours";
"permission location precise when in use description" = "Autoriser l'accès à votre localisation précise";
"permission location precise always description" = "Autoriser l'accès à votre localisation précise";
"permission tracking name" = "Suivi du site";
"permission tracking description" = "Autoriser l'accès aux données liées à l'application";
@@ -62,14 +62,6 @@
"permission location always description" = "Consenti di accedere alla tua posizione";
"permission location precise when in use name" = "Posizione precisa quando si usa";
"permission location precise always name" = "Posizione precisa sempre";
"permission location precise when in use description" = "Consenti di accedere alla tua posizione precisa";
"permission location precise always description" = "Consenti di accedere alla tua posizione precisa";
"permission tracking name" = "Tracking";
"permission tracking description" = "Consenti di accedere ai dati relativi all'app";
@@ -62,14 +62,6 @@
"permission location always description" = "Toegang tot uw locatie toestaan";
"permission location precise when in use name" = "Exacte locatie tijdens gebruik";
"permission location precise always name" = "Exacte Locatie Altijd";
"permission location precise when in use description" = "Toegang tot uw exacte locatie toestaan";
"permission location precise always description" = "Toegang tot uw exacte locatie toestaan";
"permission tracking name" = "Volgen";
"permission tracking description" = "Toegang geven tot app-gerelateerde gegevens";
@@ -62,14 +62,6 @@
"permission location always description" = "Zezwalaj na dostęp do swojej lokalizacji";
"permission location precise when in use name" = "Precyzyjna lokalizacja podczas użytkowania";
"permission location precise always name" = "Dokładna lokalizacja zawsze";
"permission location precise when in use description" = "Zezwalaj na dostęp do swojej dokładnej lokalizacji";
"permission location precise always description" = "Zezwalaj na dostęp do swojej dokładnej lokalizacji";
"permission tracking name" = "Śledzenie";
"permission tracking description" = "Zezwalaj na dostęp do danych związanych z aplikacją";
@@ -62,14 +62,6 @@
"permission location always description" = "Permitir o acesso à sua localização";
"permission location precise when in use name" = "Localização Precisa Quando Usar";
"permission location precise always name" = "Localização Precisa Sempre";
"permission location precise when in use description" = "Permitir o acesso à sua localização precisa";
"permission location precise always description" = "Permitir o acesso à sua localização precisa";
"permission tracking name" = "Rastreamento";
"permission tracking description" = "Permitir o acesso a dados relacionados com as aplicações";
@@ -62,14 +62,6 @@
"permission location always description" = "Разрешить доступ к вашему местоположению";
"permission location precise when in use name" = "Точное местоположение при использовании";
"permission location precise always name" = "Точное местоположение всегда";
"permission location precise when in use description" = "Разрешить доступ к вашему точному местоположению";
"permission location precise always description" = "Разрешить доступ к вашему точному местоположению";
"permission tracking name" = "Отслеживание";
"permission tracking description" = "Разрешить отслеживание с помощью рекламного идентификатора";
@@ -64,14 +64,6 @@
"permission tracking name" = "Відстеження";
"permission location precise when in use name" = "Точне розташування під час використання";
"permission location precise always name" = "Завжди точне розташування";
"permission location precise when in use description" = "Надайте доступ до вашого точного місцезнаходження";
"permission location precise always description" = "Надайте доступ до вашого точного місцезнаходження";
"permission tracking description" = "Дозволити доступ до даних, пов’язаних із додатками";
"permission faceid name" = "FaceID";
@@ -62,14 +62,6 @@
"permission location always description" = "取用您的位置";
"permission location precise when in use name" = "使用時精確定位";
"permission location precise always name" = "始終精確定位";
"permission location precise when in use description" = "允許訪問您的精確位置";
"permission location precise always description" = "允許訪問您的精確位置";
"permission tracking name" = "追蹤";
"permission tracking description" = "允許追蹤您在其他公司的 App 和網站上的活動";
@@ -62,14 +62,6 @@
"permission location always description" = "访问您的位置";
"permission location precise when in use name" = "使用时的精确定位";
"permission location precise always name" = "始终保持精确的位置";
"permission location precise when in use description" = "允许访问您的精确位置";
"permission location precise always description" = "允许访问您的精确位置";
"permission tracking name" = "跟踪";
"permission tracking description" = "允许访问 App 相关的数据";
@@ -220,8 +220,6 @@ public enum SPPermissions {
case faceID = 15
case siri = 16
case health = 17
case locationWhenInUsePrecise = 18
case locationAlwaysPrecise = 19
public var name: String {
switch self {
@@ -259,10 +257,6 @@ public enum SPPermissions {
return "Siri"
case .health:
return "Health"
case .locationWhenInUsePrecise:
return "Precise Location When Use "
case .locationAlwaysPrecise:
return "Precise Location Always"
}
}
}
@@ -19,8 +19,12 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#if os(iOS) && SPPERMISSIONS_LOCATION_ALWAYS
#if SPPERMISSIONS_SPM
import SPPermissions
import SPPermissionsLocationExtension
#endif
#if os(iOS) && SPPERMISSIONS_LOCATION_ALWAYS
import Foundation
import MapKit
@@ -21,6 +21,7 @@
#if SPPERMISSIONS_SPM
import SPPermissions
import SPPermissionsLocationExtension
#endif
#if os(iOS) && SPPERMISSIONS_LOCATION_ALWAYS
@@ -63,9 +64,22 @@ public class SPLocationAlwaysPermission: SPPermissions.Permission {
}
}
public var isPrecise: Bool {
#if os(iOS)
if #available(iOS 14.0, *) {
switch CLLocationManager().accuracyAuthorization {
case .fullAccuracy: return true
case .reducedAccuracy: return false
@unknown default: return false
}
}
#endif
return false
}
public override func request(completion: @escaping () -> Void) {
SPLocationAlwaysHandler.shared = SPLocationAlwaysHandler()
SPLocationAlwaysHandler.shared?.requestPermission {
SPLocationAlwaysHandler.shared?.requestPermission() {
DispatchQueue.main.async {
completion()
SPLocationAlwaysHandler.shared = nil
@@ -19,45 +19,40 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#if SPPERMISSIONS_SPM
import SPPermissions
#endif
#if os(iOS) && SPPERMISSIONS_LOCATION_ALWAYS
import Foundation
import MapKit
public extension SPPermissions.Permission {
static var locationAlwaysPrecise: SPLocationAlwaysPrecisePermission {
return SPLocationAlwaysPrecisePermission()
extension CLLocationManager {
open func setAccuracy(_ value: SPLocationAccuracy) {
desiredAccuracy = value.coreLocationAccuracy
}
}
public class SPLocationAlwaysPrecisePermission: SPLocationAlwaysPermission {
public enum SPLocationAccuracy {
public override var type: SPPermissions.PermissionType { .locationAlwaysPrecise }
case best
case bestForNavigation
case nearestTenMeters
case hundredMeters
case kilometer
case threeKilometers
case reduced
public override var status: SPPermissions.PermissionStatus {
let alwaysAuthorizationStatus = SPLocationAlwaysPermission().status
let hasPrecision: Bool = {
#if os(iOS)
if #available(iOS 14.0, *), CLLocationManager().accuracyAuthorization != .fullAccuracy {
return false
var coreLocationAccuracy: CLLocationAccuracy {
switch self {
case .best: return kCLLocationAccuracyBest
case .bestForNavigation: return kCLLocationAccuracyBestForNavigation
case .nearestTenMeters: return kCLLocationAccuracyNearestTenMeters
case .hundredMeters: return kCLLocationAccuracyHundredMeters
case .kilometer: return kCLLocationAccuracyKilometer
case .threeKilometers: return kCLLocationAccuracyThreeKilometers
case .reduced:
if #available(iOS 14.0, *) {
return kCLLocationAccuracyReduced
} else {
return kCLLocationAccuracyThreeKilometers
}
#endif
return true
}()
switch alwaysAuthorizationStatus {
#if os(iOS)
case .authorized: return hasPrecision ? .authorized : .denied
#endif
default: return alwaysAuthorizationStatus
}
}
}
#endif
@@ -21,10 +21,10 @@
#if SPPERMISSIONS_SPM
import SPPermissions
import SPPermissionsLocationExtension
#endif
#if SPPERMISSIONS_LOCATION_WHENINUSE
import Foundation
import MapKit
@@ -63,12 +63,25 @@ public class SPLocationWhenInUsePermission: SPPermissions.Permission {
}
}
public var isPrecise: Bool {
#if os(iOS)
if #available(iOS 14.0, *) {
switch CLLocationManager().accuracyAuthorization {
case .fullAccuracy: return true
case .reducedAccuracy: return false
@unknown default: return false
}
}
#endif
return false
}
public override func request(completion: @escaping () -> Void) {
SLocationWhenInUseHandler.shared = SLocationWhenInUseHandler()
SLocationWhenInUseHandler.shared?.requestPermission {
SPLocationWhenInUseHandler.shared = SPLocationWhenInUseHandler()
SPLocationWhenInUseHandler.shared?.requestPermission() {
DispatchQueue.main.async {
completion()
SLocationWhenInUseHandler.shared = nil
SPLocationWhenInUseHandler.shared = nil
}
}
}
@@ -1,63 +0,0 @@
// The MIT License (MIT)
// Copyright © 2020 Ivan Vorobei (hello@ivanvorobei.by)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#if SPPERMISSIONS_SPM
import SPPermissions
#endif
#if SPPERMISSIONS_LOCATION_WHENINUSE
import Foundation
import MapKit
public extension SPPermissions.Permission {
static var locationWhenInUsePrecise: SPLocationWhenInUsePrecisePermission {
return SPLocationWhenInUsePrecisePermission ()
}
}
public class SPLocationWhenInUsePrecisePermission: SPLocationWhenInUsePermission {
public override var type: SPPermissions.PermissionType { .locationWhenInUsePrecise}
public override var status: SPPermissions.PermissionStatus {
let whenInUseAuthorizationStatus = SPLocationWhenInUsePermission().status
let hasPrecision: Bool = {
#if os(iOS)
if #available(iOS 14.0, *), CLLocationManager().accuracyAuthorization != .fullAccuracy {
return false
}
#endif
return true
}()
switch whenInUseAuthorizationStatus {
#if os(iOS)
case .authorized: return hasPrecision ? .authorized : .denied
#endif
default: return whenInUseAuthorizationStatus
}
}
}
#endif
@@ -19,12 +19,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#if SPPERMISSIONS_LOCATION_WHENINUSE
#if SPPERMISSIONS_SPM
import SPPermissions
import SPPermissionsLocationExtension
#endif
#if SPPERMISSIONS_LOCATION_WHENINUSE
import Foundation
import MapKit
class SLocationWhenInUseHandler: NSObject, CLLocationManagerDelegate {
class SPLocationWhenInUseHandler: NSObject, CLLocationManagerDelegate {
// MARK: - Location Manager
@@ -45,7 +49,6 @@ class SLocationWhenInUseHandler: NSObject, CLLocationManagerDelegate {
self.completionHandler = completionHandler
let status = CLLocationManager.authorizationStatus()
switch status {
case .notDetermined:
locationManager.delegate = self
@@ -60,7 +63,7 @@ class SLocationWhenInUseHandler: NSObject, CLLocationManagerDelegate {
// MARK: - Init
static var shared: SLocationWhenInUseHandler?
static var shared: SPLocationWhenInUseHandler?
override init() {
super.init()
+2
View File
@@ -7,3 +7,5 @@ Here provided ideas or features which will be implemented soon.
- Special screen with explain for `Tracking` permission.
- Loading animation for action button for permission.
- Redo present process to native present method.
- Fixed fonts sizing.
- Added bottom sheet with gester style for present.