I would be interested in knowing how to add a calendar event in the device, but using swift. I know there are some examples made in Objective-C, but at the moment nothing in swift. Many thanks.
相关问题
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
- Get the NSRange for the visible text after scroll
- UIPanGestureRecognizer is not working in iOS 13
- What does a Firebase observer actually do?
相关文章
- Using if let syntax in switch statement
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
- How can I vertically align my status bar item text
- Adding TapGestureRecognizer to UILabel in Swift
- Attempt to present UIAlertController on View Contr
- Swift - Snapshotting a view that has not been rend
Swift 3.0 version
Reference : https://gist.github.com/mchirico/d072c4e38bda61040f91
Swift 3.0 compatible:
And also import
EventKit
So you can easily call this method from everywhere:
If you prefer, you can put this method inside an utiliy class and define it as 'static'.
I was able to adjust this and eliminate the compiler error mentioned in the comments to the answers above (and a few others), as follows:
However, I still get the following error at the bottom regarding "EKSpan.ThisEvent" : Incorrect argument label in call (have ':span:error:', expected ':span:commit:').
I tried changing "error" to "commit," but it gave me a compiler error saying it expected a Bool instead of nil. It seems like a problem having to do with updates in swift syntax.
Edit: I ended up following this tutorial and was able to get it to work.
First, ask permission to access the calendar and (if that permission is granted) call a function to add the event.
The function that is called in the above code snippet to add the event:
This was really slow on iOS 11.2 Xcode 9.2, so I modified Luca Davanzo's answer to use queues (works a lot faster):
You need to add "Privacy - Calendars Usage Description" to info.plist. Following code works with latest version of xcode and swift 3.