Skip to content

Commit

Permalink
Added support visionOS & macOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed Jul 10, 2024
1 parent 8f92c79 commit f10828f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
9 changes: 5 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// swift-tools-version:5.3
// swift-tools-version: 5.9

import PackageDescription

let package = Package(
name: "PermissionsKit",
defaultLocalization: "en",
platforms: [
.iOS(.v11),
.tvOS(.v11),
.watchOS(.v3)
.iOS(.v12),
.tvOS(.v12),
.watchOS(.v4),
.macOS(.v13)
],
products: [
.library(
Expand Down
2 changes: 1 addition & 1 deletion 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 = "10.0.1"
s.version = "11.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
11 changes: 10 additions & 1 deletion Sources/BluetoothPermission/BluetoothHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ class BluetoothHandler: NSObject, CBCentralManagerDelegate {

func centralManagerDidUpdateState(_ central: CBCentralManager) {
if #available(iOS 13.0, tvOS 13, *) {
switch central.authorization {

let authorization: CBManagerAuthorization = {
#if os(visionOS)
return CBManager.authorization
#else
return central.authorization
#endif
}()

switch authorization {
case .notDetermined:
break
default:
Expand Down
16 changes: 14 additions & 2 deletions Sources/LocationPermission/Handlers/LocationWhenInUseHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ class LocationWhenInUseHandler: NSObject, CLLocationManagerDelegate {

lazy var locationManager = CLLocationManager()

#if !os(visionOS)
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if status == .notDetermined {
return
}
completionHandler()
}
#endif


@available(iOS 14.0, *)
@available(iOS 14.0, macOS 11.0, watchOS 7.0, tvOS 14.0, visionOS 1.0, *)
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
if manager.authorizationStatus == .notDetermined {
return
Expand All @@ -55,7 +58,16 @@ class LocationWhenInUseHandler: NSObject, CLLocationManagerDelegate {
func requestPermission(_ completionHandler: @escaping () -> Void) {
self.completionHandler = completionHandler

let status = CLLocationManager.authorizationStatus()
let status: CLAuthorizationStatus = {
#if os(visionOS)
locationManager.authorizationStatus
#elseif os(macOS)
locationManager.authorizationStatus
#else
CLLocationManager.authorizationStatus()
#endif
}()

switch status {
case .notDetermined:
locationManager.delegate = self
Expand Down
2 changes: 1 addition & 1 deletion Sources/PermissionsKit/Data/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import UIKit
import Foundation

enum Texts {

Expand Down
6 changes: 6 additions & 0 deletions Sources/PermissionsKit/Permission.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import Foundation

#if os(iOS)
import UIKit
#endif

open class Permission {

Expand Down Expand Up @@ -48,6 +52,7 @@ open class Permission {
For most permissions its app page in settings app.
You can overide it if your permission need open custom page.
*/
#if os(iOS)
@available(iOSApplicationExtension, unavailable)
open func openSettingPage() {
DispatchQueue.main.async {
Expand All @@ -57,6 +62,7 @@ open class Permission {
}
}
}
#endif

// MARK: Must Ovveride

Expand Down

0 comments on commit f10828f

Please sign in to comment.