Comments (15)
@ivanvorobei @ostatnicky
to fix the issue with initial result is always .notDetermined
we could add an @available(iOS 17.0, *) func request() async -> Status
to class Permission
.
this could look like this:
@available(iOS 17.0, *)
public override func request() async -> Status {
let eventStore = EKEventStore()
return await withCheckedContinuation { continuation in
switch kind {
case .calendar(let access):
switch access {
case .full:
eventStore.requestFullAccess { (isGranted: Bool, error: Error?) in
continuation.resume(returning: isGranted ? .authorized : .denied)
}
case .write:
eventStore.requestWriteOnlyAccess { (isGranted: Bool, error: Error?) in
continuation.resume(returning: isGranted ? .authorized : .denied)
}
}
default:
continuation.resume(returning: .notDetermined)
}
}
}
this could then be used within apps like:
let status = await Permission.calendar(access: .full).request()
helper methods for EKEventStore
can clean up code, so you don't have to write those requestFullAccess
or requestWriteOnlyAccess
again and again.
private extension EKEventStore {
typealias EventStoreAction = ((isGranted: Bool, error: Error?)) -> Void
func requestFullAccess(completion: @escaping EventStoreAction) {
if #available(iOS 17.0, *) {
self.requestFullAccessToEvents { (accessGranted: Bool, error: Error?) in
DispatchQueue.main.async {
completion((isGranted: accessGranted, error: error))
}
}
} else {
self.requestAccess(to: EKEntityType.event) { (accessGranted: Bool, error: Error?) in
DispatchQueue.main.async {
completion((isGranted: accessGranted, error: error))
}
}
}
}
func requestWriteOnlyAccess(completion: @escaping EventStoreAction) {
if #available(iOS 17.0, *) {
self.requestWriteOnlyAccessToEvents { (accessGranted: Bool, error: Error?) in
DispatchQueue.main.async {
completion((isGranted: accessGranted, error: error))
}
}
}
}
}
the default request(completion: @escpaing () ->Void))
could then be refactored like this:
public override func request(completion: @escaping () -> Void) {
let eventStore = EKEventStore()
if #available(iOS 17.0, *) {
switch kind {
case .calendar(let access):
switch access {
case .full:
eventStore.requestFullAccess { (isGranted: Bool, error: Error?) in
completion()
}
case .write:
eventStore.requestWriteOnlyAccess { (isGranted: Bool, error: Error?) in
completion()
}
}
default:
completion()
}
} else {
eventStore.requestFullAccess { (isGranted: Bool, error: Error?) in
completion()
}
}
}
from permissionskit.
Yes, it looks really promising! Thanks for the effort, Alex.
from permissionskit.
but this sounds more like an issue in general with this calendar permissions, right? did you check if there is already a reported bug on apple side available?
from permissionskit.
Does it matter if it’s Apple’s bug or not? The current flow doesn’t work and you’re responsible to react on it and provide a solution for it (and it exists and I told you it).
To be honest, I’m removing this pod from my project because it seems out-dated and you don’t care about it, you don’t test PRs. Someone told you in July that there are changes in iOS 17 but you didn’t even think about it. So it’s better to have my own solution than always debug why PermissionKit doesn’t work :/
from permissionskit.
Not sure why you are so rude? This isn't even my package, I just provided a solution for iOS 17 which was recommended by apples migration guide. 😅
from permissionskit.
Ah, you’re different guy :D Sorry both, I was very upset and spent whole day to make it work and expected just to update the pod…
from permissionskit.
@ostatnicky I see you upset with bug, but its open source. Its just happen.
from permissionskit.
PR merged, new release pushed.
from permissionskit.
you can find the changes here: alexanderpuchta@e0e9c61
from permissionskit.
yup, but this would mean an entire update of that framework. not sure if @ivanvorobei will do this at the moment
from permissionskit.
yup, but this would mean an entire update of that framework. not sure if @ivanvorobei will do this at the moment
I will check it today, I see it's important to achieve
from permissionskit.
Alex's code works well, I've tested. Let's take a look on the response:
continuation.resume(returning: isGranted ? .authorized : .denied)
I'm not sure if we should return Permission.Status
. Because the status
could be really different. Sometimes the access is not granted just because it's not determined and not because of it was denied.
So I suggest to have something like this:
public override func request() async -> (isGranted: Bool, error: Error?)
Yeah, the solution is not straightforward... :D
from permissionskit.
I wouldn't like that, to return a tuple.
I would recommend
func request() async throw -> Status
or change continuation.resume
to
let status: Status = {
if let error != nil {
return .notDetermined
}
return isGranted ? .authorized : .denied
}()
continuation.resume(returning: status)
from permissionskit.
@ostatnicky thanks for you debug. Honestly I don't see clear your point with opensource and its look little negative. But anyway, we are community.
I did some research with it and for sure it's apple's bug. But good news - I have clean solution. I resecah and got result of state wrong only first time. I just added empty call which not return for state. Next call response with right value.
let _ = EKEventStore.authorizationStatus(for: EKEntityType.event)
I add this line and now its work well. New release preparing and hope its looks better than use async call.
Anyway @alexanderpuchta thanks for your reseach.
If my solution not work let me know please.
from permissionskit.
Release 9.2.2 available.
from permissionskit.
Related Issues (20)
- Suggestion: add callback method to determine whether to authorize status HOT 3
- SPPermissions library has Adware inside! HOT 1
- How to modify the default description HOT 1
- iOS 17: Migrating to the new Calendar access levels HOT 1
- iOS 17: Migrating to the new Calendar access levels HOT 6
- ReminderPermission update with write-only access (iOS 17) HOT 3
- SPPermissionsDataSource not found HOT 1
- Fixed struct of Location permissions. Merge to one permission with types.
- Will Apple accept app? HOT 2
- client implementation missing? HOT 6
- Missing package product 'LocationWhenInUsePermission' HOT 1
- Request FaceID permission always return notDetermined HOT 2
- LocationWhenInUsePermission is incompatible HOT 1
- Still having issues with Location Always HOT 2
- Privacy Manifest support HOT 1
- New iOS 17 requestFullAccessToEvents returns always notDetermined on first run in Reminder HOT 2
- Permission.location(access: .always).request { } 不可以正确回调 HOT 2
- Permission.location(access: .always).request {} HOT 4
- Permission.location(access: .always).request {} bad HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from permissionskit.