Skip to content

Commit

Permalink
Added FaceID Permission.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed Jun 6, 2021
1 parent 479f561 commit 47007b7
Show file tree
Hide file tree
Showing 19 changed files with 130 additions and 26 deletions.
Binary file added Assets/Permissions/faceid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file modified Assets/Sketch/sppermissions-v6.sketch
Binary file not shown.
5 changes: 3 additions & 2 deletions Example Apps/Dependencies/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ let package = Package(
.product(name: "SPPermissionsLocationWhenInUse", package: "SPPermissions"),
.product(name: "SPPermissionsLocationAlways", package: "SPPermissions"),
.product(name: "SPPermissionsMotion", package: "SPPermissions"),
.product(name: "SPPermissionsMediaLibrary", package: "SPPermissions"),
.product(name: "SPPermissionsMusic", package: "SPPermissions"),
.product(name: "SPPermissionsBluetooth", package: "SPPermissions"),
.product(name: "SPPermissionsTracking", package: "SPPermissions")
.product(name: "SPPermissionsTracking", package: "SPPermissions"),
.product(name: "SPPermissionsFaceID", package: "SPPermissions")
]
),
]
Expand Down
Binary file not shown.
5 changes: 3 additions & 2 deletions Example Apps/iOS Example/Scenes/RootController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ import SPPermissionsSpeechRecognizer
import SPPermissionsLocationWhenInUse
import SPPermissionsLocationAlways
import SPPermissionsMotion
import SPPermissionsMediaLibrary
import SPPermissionsMusic
import SPPermissionsBluetooth
import SPPermissionsTracking
import SPPermissionsFaceID

class RootController: SPTableViewController {

var availablePermissions: [SPPermissions.Permission] = [.camera, .photoLibrary, .notification, .microphone, .calendar, .contacts, .reminders, .speech, .locationWhenInUse, .locationAlways, .motion, .mediaLibrary, .bluetooth, /*.tracking*/]
var availablePermissions: [SPPermissions.Permission] = [.camera, .photoLibrary, .notification, .microphone, .calendar, .contacts, .reminders, .speech, .locationWhenInUse, .locationAlways, .motion, .mediaLibrary, .bluetooth, /*.tracking,*/ .faceID]

var selectedPermissions: [SPPermissions.Permission] = []

Expand Down
20 changes: 16 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ let package = Package(
targets: ["SPPermissionsMotion"]
),
.library(
name: "SPPermissionsMediaLibrary",
targets: ["SPPermissionsMediaLibrary"]
name: "SPPermissionsMusic",
targets: ["SPPermissionsMusic"]
),
.library(
name: "SPPermissionsBluetooth",
Expand All @@ -67,6 +67,10 @@ let package = Package(
name: "SPPermissionsTracking",
targets: ["SPPermissionsTracking"]
),
.library(
name: "SPPermissionsFaceID",
targets: ["SPPermissionsFaceID"]
),
],
dependencies: [],
targets: [
Expand Down Expand Up @@ -168,10 +172,10 @@ let package = Package(
]
),
.target(
name: "SPPermissionsMediaLibrary",
name: "SPPermissionsMusic",
dependencies: [.target(name: "SPPermissions")],
swiftSettings: [
.define("SPPERMISSIONS_MEDIALIBRARY"),
.define("SPPERMISSIONS_MUSIC"),
.define("SPPERMISSIONS_SPM")
]
),
Expand All @@ -190,6 +194,14 @@ let package = Package(
.define("SPPERMISSIONS_TRACKING"),
.define("SPPERMISSIONS_SPM")
]
),
.target(
name: "SPPermissionsFaceID",
dependencies: [.target(name: "SPPermissions")],
swiftSettings: [
.define("SPPERMISSIONS_FACEID"),
.define("SPPERMISSIONS_SPM")
]
)
],
swiftLanguageVersions: [.v5]
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ If you like the project, don't forget to `put star ★` and follow me on GitHub:
<img src="https://github.com/ivanvorobei/SPPermissions/blob/main/Assets/Permissions/contacts.png" width="38">
<img src="https://github.com/ivanvorobei/SPPermissions/blob/main/Assets/Permissions/reminders.png" width="38">
<img src="https://github.com/ivanvorobei/SPPermissions/blob/main/Assets/Permissions/motion.png" width="38">
<img src="https://github.com/ivanvorobei/SPPermissions/blob/main/Assets/Permissions/media.png" width="38">
<img src="https://github.com/ivanvorobei/SPPermissions/blob/main/Assets/Permissions/music.png" width="38">
<img src="https://github.com/ivanvorobei/SPPermissions/blob/main/Assets/Permissions/speech.png" width="38">
<img src="https://github.com/ivanvorobei/SPPermissions/blob/main/Assets/Permissions/bluetooth.png" width="38">
<img src="https://github.com/ivanvorobei/SPPermissions/blob/main/Assets/Permissions/tracking.png" width="38">
<img src="https://github.com/ivanvorobei/SPPermissions/blob/main/Assets/Permissions/faceid.png" width="38">
</p>

## Navigate
Expand Down Expand Up @@ -123,14 +124,17 @@ pod 'SPPermissions/LocationAlways'
pod 'SPPermissions/Motion'
```
```ruby
pod 'SPPermissions/MediaLibrary'
pod 'SPPermissions/Music'
```
```ruby
pod 'SPPermissions/Bluetooth'
```
```ruby
pod 'SPPermissions/Tracking'
```
```ruby
pod 'SPPermissions/FaceID'
```

</p>
</details>
Expand Down Expand Up @@ -350,6 +354,7 @@ List of keys:
- NSBluetoothAlwaysUsageDescription
- NSBluetoothPeripheralUsageDescription (iOS 12 and earlier)
- NSUserTrackingUsageDescription
- NSFaceIDUsageDescription

Do not use the description as the name of the key.

Expand Down
8 changes: 4 additions & 4 deletions SPPermissions.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SPPermissions"
s.version = "6.4.1"
s.version = "6.4.4"
s.summary = "Ask permissions on Swift. Available List, Dialog & Native interface. Can check state permission."
s.homepage = "https://github.com/ivanvorobei/SPPermissions"
s.source = { :git => "https://github.com/ivanvorobei/SPPermissions.git", :tag => s.version }
Expand Down Expand Up @@ -119,11 +119,11 @@ Pod::Spec.new do |s|
}
end

s.subspec 'MediaLibrary' do |subspec|
s.subspec 'Music' do |subspec|
subspec.dependency 'SPPermissions/Core'
subspec.source_files = "Sources/SPPermissionsMediaLibrary/**/*.swift"
subspec.source_files = "Sources/SPPermissionsMusic/**/*.swift"
subspec.pod_target_xcconfig = {
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "SPPERMISSIONS_MEDIALIBRARY SPPERMISSIONS_COCOAPODS"
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "SPPERMISSIONS_Music SPPERMISSIONS_COCOAPODS"
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public class SPPermissionsDrawIconView: UIView {
Draw.drawBluetooth(frame: rect, resizing: .aspectFit, color: tintColor)
case .tracking:
Draw.drawTracking(frame: rect, resizing: .aspectFit, color: tintColor)
case .faceID:
// Not implemented old style icons.
break
case .none:
break
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
"filename" : "FaceID.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@

"permission tracking description" = "Allow to access app-related data";

"permission faceid name" = "FaceID";

"permission faceid description" = "Allow using Face ID identity.";

"denied alert title" = "Permission denied";

"denied alert description" = "Please, go to Settings and allow permission.";
Expand Down
4 changes: 4 additions & 0 deletions Sources/SPPermissions/SPPermissions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public enum SPPermissions {
case authorized
case denied
case notDetermined
case notSupported
}

/**
Expand All @@ -172,6 +173,7 @@ public enum SPPermissions {
case mediaLibrary = 12
case bluetooth = 13
case tracking = 14
case faceID = 15

public var name: String {
switch self {
Expand Down Expand Up @@ -203,6 +205,8 @@ public enum SPPermissions {
return "Location When Use"
case .tracking:
return "Tracking"
case .faceID:
return "FaceID"
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/SPPermissions/Services/Images.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ enum Images {
return UIImage.init(named: "Location", in: bundle, compatibleWith: nil) ?? UIImage()
case .tracking:
return UIImage.init(named: "Tracking", in: bundle, compatibleWith: nil) ?? UIImage()
case .faceID:
return UIImage.init(named: "FaceID", in: bundle, compatibleWith: nil) ?? UIImage()
}
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/SPPermissions/Services/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ enum Texts {
return NSLocalizedString("permission location always name", bundle: bundle, comment: "")
case .tracking:
return NSLocalizedString("permission tracking name", bundle: bundle, comment: "")
case .faceID:
return NSLocalizedString("permission faceid name", bundle: bundle, comment: "")
}
}

Expand Down Expand Up @@ -86,6 +88,8 @@ enum Texts {
return NSLocalizedString("permission location always description", bundle: bundle, comment: "")
case .tracking:
return NSLocalizedString("permission tracking description", bundle: bundle, comment: "")
case .faceID:
return NSLocalizedString("permission faceid description", bundle: bundle, comment: "")
}
}

Expand Down
74 changes: 74 additions & 0 deletions Sources/SPPermissionsFaceID/SPFaceIDPermission.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// The MIT License (MIT)
// Copyright © 2020 Ivan Vorobei ([email protected])
//
// 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 os(iOS) && SPPERMISSIONS_FACEID

import Foundation
import LocalAuthentication

public extension SPPermissions.Permission {

static var faceID: SPFaceIDPermission {
return SPFaceIDPermission()
}
}

public class SPFaceIDPermission: SPPermissions.Permission {

open override var type: SPPermissions.PermissionType { .faceID }
open var usageDescriptionKey: String? { "NSFaceIDUsageDescription" }

public override var status: SPPermissions.PermissionStatus {
let context = LAContext()

var error: NSError?
let isReady = context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error)

guard context.biometryType == .faceID else {
return .notSupported
}

switch error?.code {
case nil where isReady:
return .notDetermined
case LAError.biometryNotAvailable.rawValue:
return .denied
case LAError.biometryNotEnrolled.rawValue:
return .notSupported
default:
return .notSupported
}
}

public override func request(completion: @escaping () -> Void) {
LAContext().evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: " ") { _, _ in
DispatchQueue.main.async {
completion()
}
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import SPPermissions
#endif

#if os(iOS) && SPPERMISSIONS_MEDIALIBRARY
#if os(iOS) && SPPERMISSIONS_MUSIC

import Foundation
import MediaPlayer
Expand Down

0 comments on commit 47007b7

Please sign in to comment.