Comments (14)
Hi, thanks for pointing this out. The issue with clean simulator appears to be related to Calendar not being yet initialized. Someone added info to README about this which I just merged.
Thanks for the clarification, I will look into it. Or if you want, you can try to fix the SwiftUI example and open PR :-)
from ekeventkit.example.
I've spent quite some time on the errors but I can't seem to find a solution, or even a source. I will continue digging but it would be great if you can take a look as well. I don't trust my SwiftUI skills yet 😀
For some reason I think the errors and the empty calendar list are related. As I mentioned, if I run the app on my daily driver device I still get the errors and an empty calendar list the first time the app is started after a clean install. On this device the calendar is definitely initiated.
Is almost like the available calendars are not refreshed after you accept calendar access.
from ekeventkit.example.
One step forward, two steps back.
I did some experiments and I might have found something that can be of help.
In the EventsRepository.swift, if you change let eventStore = EKEventStore()
to var eventStore = EKEventStore()
and then change the requestAccess
function to:
func requestAccess(onGranted: @escaping Action, onDenied: @escaping Action) {
eventStore.requestAccess(to: .event) { (granted, error) in
if granted {
self.eventStore = EKEventStore()
onGranted()
} else {
onDenied()
}
}
}
By doing this the calendar list is populated directly. However, this causes a bunch of other errors, like a EKEvent duplicate key error if you add an event. As mentioned, I was experimenting but it might be worth taking a closer look.
from ekeventkit.example.
Thanks. I will try to look into it, but I havent done much of SwiftUI since creating this update..
from ekeventkit.example.
Sorry for hammering you with posts and information, but here is a SO post with the exact same issue. The possible solution seems to be to "Make sure you aren't initializing EKEventStore before requesting calendar permissions."
from ekeventkit.example.
Thanks for the search. However you need an instance of EKEventStore to request permissions 🤔 You said UIKit version is working fine? Since there the EKEventStore is created immediately by the view controller.
from ekeventkit.example.
Hm, weird . I have not tested the UIKit version.
I also found this in apples documentation on EKEventStore
"If your app has never requested access before, you must request access to events or reminders before attempting to fetch or create them. If you request data before prompting the user for access with this method, you’ll need to reset the event store with the reset() method in order to start receiving data after the user grants access."
https://developer.apple.com/documentation/eventkit/ekeventstore/1507547-requestaccess
Something like eventStore.reset(), I guess. But I'm not sure where to reset the event store?
from ekeventkit.example.
Based on the docs it makes sense to call reset
before the onGranted
closure is called in the requestAccess
method. I dont have access to my Mac right now so I cannot try this.
from ekeventkit.example.
Unfortunately no luck. I'm really struggling with this, so if you could take a look I would really appreciate it. This is basically the last piece of my app puzzle :)
from ekeventkit.example.
I will try to fix this issue 👍
from ekeventkit.example.
Great! I've experimented with another thing and this might be the definition of bad coding, I don't know :) But it seems to work so maybe you can take some inspiration from it.
I added the requestAccess function to the top of init(), like this:
init() {
requestAccess(onGranted: {
self.eventStore = EKEventStore()
}) {
}
...
}
So when we gain access I'm getting a new eventStore
instance. If this is usable, I don't know if you need to requestAccess
in the loadEvents
function?
Also, I came across authorizationStatus(for:)
which seems to be used as a check on which you can act on the current status (authorized, denied, notDetermined, restricted).
https://developer.apple.com/documentation/eventkit/ekeventstore/1507239-authorizationstatus
from ekeventkit.example.
Think I found it:
selectedCalendars = loadSelectedCalendars() ?? Set([eventStore.defaultCalendarForNewEvents].compactMap({ $0 }))
This line was likely responsible for accessing eventStore
before permissions were available and thus causing the issues. If you remove the ??
part, then it works.
I have updated the repo with this fix:
selectedCalendars = loadSelectedCalendars()
if selectedCalendars == nil {
if EKEventStore.authorizationStatus(for: .event) == .authorized {
selectedCalendars = Set([eventStore.defaultCalendarForNewEvents].compactMap({ $0 }))
}
}
from ekeventkit.example.
Amazing Filip, just tested the fix and it seems to work perfectly!
I also noticed that the errors I mentioned in my first post seems to be gone as well :)
Thank you and great job!
from ekeventkit.example.
Awesome! Thanks for help fixing this :-)
from ekeventkit.example.
Related Issues (9)
- Any chance of a swiftUI version of this? I've found information of EventKit & EventKitui rarer than unicorn S*!t HOT 4
- Relative time giving odd results HOT 4
- Suggestion to break list into day segments HOT 9
- Selected Calendars not being persisted HOT 1
- Recurring events issue HOT 11
- EKEventEditViewController initial focus HOT 2
- Refresh events when app is reopened/brought to foreground HOT 12
- iOS 15, "bottom sheet" HOT 3
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 ekeventkit.example.