EKEvent accept invitation
Turns out, after doing some more research, that all of these apps are just displaying the EKEventViewController
. What I had mistaken as customization was actually view tints.
How can I display the details of a EKEvent invitation within my app using EKEventViewController?
I finally solved it. It looks like apart from Calendar permission I need also to add into the info.plist Contacts permission.
Privacy - Contacts Usage Description
Is there a way to modify my attendance status using iOS EventKit?
I just used EventKitUI and it works.
EKEvent event.eventIdentifier not removing
I figured it out. Because eventStore.requestAccess(to: .event)
is asynchronous, I was saving the event id in the database before the id existed.
So I had to declare the function to accept a completion handler and return the value inside the completion handler.
//// adding events to calendar
func addEventToCalendar(userName: String, userDate: Date, completion: @escaping (String?)->()) {
let userDefaults = UserDefaults.standard
var eventId = ""
let eventStore: EKEventStore = EKEventStore()
eventStore.requestAccess(to: .event) { (granted, error) in
if (granted) && (error == nil) {
print("granted \(granted)")
print("error \(String(describing: error))")
let event: EKEvent = EKEvent(eventStore: eventStore)
event.title = "\(userName) \(NSLocalizedString("birthday", comment: "birthday"))"
event.startDate = userDate
event.endDate = userDate
event.notes = NSLocalizedString("happyBirthday", comment: "happyBirthday")
event.isAllDay = true
event.calendar = eventStore.defaultCalendarForNewEvents
let ekrules: EKRecurrenceRule = EKRecurrenceRule.init(recurrenceWith: .yearly, interval: 1, end: nil)
event.recurrenceRules = [ekrules]
//event.addAlarm(EKAlarm(absoluteDate: event.startDate))
//sets alert 00:00 on day of event
event.addAlarm(EKAlarm(relativeOffset: 0))
do {
try eventStore.save(event, span: .futureEvents, commit: true)
eventId = event.eventIdentifier ?? "no-Id"
print("Event has been saved with id \(String(describing: eventId))")
userDefaults.setValue(eventId, forKey: "eventId")
} catch let error as NSError {
print("error: \(error)")
}
completion(eventId)
} else {
print("error not granted: \(String(describing: error))")
completion(nil)
}
}
}
and then use it like so
addEventToCalendar(userName: uName, userDate: uDate) { (eventIdentifier) in
if let eventId = eventIdentifier {
print("Event add birthday id \(eventId)")
//// saving data to device
// run on main thread to avoid 'RLMException', reason: 'Realm accessed from incorrect thread.'
DispatchQueue.main.async {
let newItem = Item()
newItem.userImageName = String(describing: self.userImageUrl)
newItem.userName = uName
newItem.isYearPresent = uYearPresent
newItem.userDOB = uDOB
newItem.color = UIColor.init(randomFlatColorOf: .dark).hexValue()
newItem.daysRemaining = daysRemain
newItem.eventId = eventId
self.save(item: newItem)
// review app
self.review()
}
EventKit : Is there any way to remove Invitees from EKEventEditViewController
I presume your talking about the displaying of the invitees and repeat options
from EKEventEditViewController?
Having looked at the current API for EKEventEditViewController it doesn't look like there is a way.
However, you could create a custom view controller that replicated the look of the EKEventEditViewController minus the event options you are not interested. You'd need to construct the interface, code the view controller and a delegate interface. It's more effort than using EKEventEditViewController but I can't see you achieving what you want any other way.
Related Topics
How to Disable Qlpreviewcontroller Print Button
Hide Status Bar and Increase the Height of Uinavigationbar
Creating an Image Out of the iOS Surface and Saving It
Accessing Objective-C Base Class's Instance Variables from a Swift Class
Using Wcsession with More Than One Viewcontroller
Nsindexpath? Does Not Have a Member Name 'Row' Error in Swift
Uialertcontroller Set Attributed Messages
Animation Blocks Resets to Original Position After Updating Text
Nsurlcache Does Not Clear Stored Responses in iOS8
Uiapplicationlaunchoptionsremotenotificationkey Not Getting Userinfo
Download PDF and Save to the "Files" in Iphone, Not to the App Data, Swift
Replace iOS App Emoji with Twitter Open Source Twemoji
How to Use Avcapturephotooutput to Capture Photo Swift + Xcode
How to Access User Defined Runtime Attribute from the 'Sender' Object
How to Calculate Current Location in Watchkit Extension