-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add API boilerplate for new calendar and reminder Addresses iOS 17 API changes * Abstract calendar/reminder into event manager * Fix obsolete API mark and revise message * Squashed commit of the following: commit 5ecef99e3b2ef04a2a05b34509e8a449031d92c4 Author: Jevon Mao <[email protected]> Date: Tue Aug 8 20:13:01 2023 -0400 Add documentation snippet for permission managers commit 44e3f41 Author: Jevon Mao <[email protected]> Date: Mon Aug 7 14:41:46 2023 -0400 Implement custom permission description color (#137) commit f3ed32c Author: Jevon Mao <[email protected]> Date: Mon Aug 7 12:58:42 2023 -0400 Disable stale check CICD * Erase type for custom foreground color * Add NSLog warning deprecated EventKit permissisons * Remove available limitation
- Loading branch information
Showing
32 changed files
with
325 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...Managers/PermissionManagerProctocol.swift → ...missionManagers/AuthorizationStatus.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Sources/CorePermissionsSwiftUI/Model/PermissionManagers/EventPermissionManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// EventPermissionManager.swift | ||
// PermissionsSwiftUI-Example | ||
// | ||
// Created by Jevon Mao on 8/26/23. | ||
// | ||
|
||
import Foundation | ||
import EventKit | ||
|
||
open class EventPermissionManager: PermissionManager { | ||
public init(requestedAccessLevel: AccessLevel = .legacy) { | ||
self.requestedAccessLevel = requestedAccessLevel | ||
if requestedAccessLevel == .legacy { | ||
NSLog("[PermissionsSwiftUI]: WARNING! Using legacy calendar or reminder permission, which will NOT work in iOS 17 and always return denied due to Apple EventKit API changes. Learn more: https://developer.apple.com/documentation/eventkit/accessing_the_event_store") | ||
} | ||
} | ||
|
||
|
||
public var requestedAccessLevel: AccessLevel | ||
public let eventStore = EKEventStore() | ||
open var entityType: EKEntityType { | ||
get { | ||
preconditionFailure("This property must be overridden.") | ||
} | ||
} | ||
|
||
public enum AccessLevel { | ||
case writeOnly | ||
case full | ||
case legacy | ||
} | ||
|
||
public override var authorizationStatus: AuthorizationStatus { | ||
switch EKEventStore.authorizationStatus(for: entityType){ | ||
case .authorized: | ||
return .authorized | ||
case .notDetermined: | ||
return .notDetermined | ||
default: | ||
return .denied | ||
} | ||
} | ||
|
||
public func requestLegacyPermission( _ completion: @escaping (Bool, Error?) -> Void) { | ||
eventStore.requestAccess(to: entityType, completion: { | ||
(accessGranted: Bool, error: Error?) in | ||
DispatchQueue.main.async { | ||
completion(accessGranted, error) | ||
} | ||
}) | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
Sources/CorePermissionsSwiftUI/Model/PermissionManagers/PermissionManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// PermissionManager.swift | ||
// PermissionsSwiftUI-Example | ||
// | ||
// Created by Jevon Mao on 8/26/23. | ||
// | ||
|
||
import Foundation | ||
|
||
/** | ||
A Permission Manager object that contains properties and functions related to a specific permission. Will be subclassed by any permission type. | ||
|
||
- warning: `PermissionManager` shoud never be referenced directly and used. It serves as an abstract interface for PermissionsSwiftUI's many permission modules. | ||
*/ | ||
open class PermissionManager: NSObject, Identifiable { | ||
///Holds the permission UI component, containing UI elements like text and image | ||
open var permissionComponent: JMPermission { | ||
get { | ||
preconditionFailure("This property must be overridden.") | ||
} | ||
} | ||
///The type of permission | ||
open var permissionType: PermissionType { | ||
preconditionFailure("This property must be overridden.") | ||
} | ||
|
||
///The authorization status of the permission | ||
open var authorizationStatus: AuthorizationStatus { | ||
get { | ||
preconditionFailure("This property must be overridden.") | ||
} | ||
} | ||
|
||
#if PERMISSIONSWIFTUI_HEALTH | ||
|
||
///Holds the health permission subcategories, in case of health permission type subclass | ||
open var healthPermissionCategories: Set<HKSampleType>? | ||
|
||
/** | ||
Creates a new `PermissionManager` for health permission. | ||
|
||
- parameters: | ||
- healthPermissionCategories: Subcategory permissions of health permission to request | ||
*/ | ||
public init(_ healthPermissionCategories: Set<HKSampleType>? = nil) { | ||
self.healthPermissionCategories = healthPermissionCategories | ||
} | ||
#else | ||
///Creates a new `PermissionManager` for any type of child implemented permission | ||
public override init() {} | ||
#endif | ||
|
||
/** | ||
Requests authorization for the current implemented type of permission. | ||
|
||
- parameters: | ||
- completion: Returns back whether the permission authorization is granted, and any errors | ||
*/ | ||
open func requestPermission(completion: @escaping (Bool, Error?) -> Void) { | ||
preconditionFailure("This method must be overridden.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.