1

I have the following code for the creation of an event in Swift 3 -

    let calEvent = EKEventStore()

    let newEvent = EKEvent(eventStore: calEvent)

    newEvent.title = self.event.title // Sets event title

    // Formats the date and time to be useable by iOS calendar app
    let formatter = DateFormatter()
    formatter.dateStyle = DateFormatter.Style.medium
    formatter.timeStyle = DateFormatter.Style.short
    let newEventStartTime = formatter.date(from: self.event.timeStart)
    let newEventEndTime = formatter.date(from: self.event.timeEnd)

    newEvent.startDate = newEventStartTime! // Sets start date and time for event
    newEvent.endDate = newEventEndTime! // Sets end date and time for event
    newEvent.location = self.event.location // Copies location into calendar
    newEvent.calendar = calEvent.defaultCalendarForNewEvents // Copies event into calendar
    newEvent.notes = self.event.description // Copies event description into calendar

I would like to use this event to add an attachment to an email using MFMailComposeViewController. I'm using this to create the email -

    if MFMailComposeViewController.canSendMail() {

        let mail = MFMailComposeViewController()
        mail.mailComposeDelegate = self
        mail.setToRecipients(recipients)
        mail.setMessageBody(mailBody, isHTML: true) // mailBody is a set string declared elsewhere.

        mail.addAttachmentData(______, mimeType: ______, fileName: _______)

        present(mail, animated: true)

    } else {

        // Show failure alert
    }

I'm confused as to how I fill out the mail.addAttachmentData() parameters. How do I convert the event to data for the for first one, and what mimeType would I use if I wanted the attachment to be a .ics file?

  • Looks like this post has already answered your question: http://stackoverflow.com/questions/18096065/attach-ical-file-in-mfmailcomposercontroller – karnett Jan 19 '17 at 20:45

0 Answers0