How to share a Calendar Event via a ShareLink

122 views Asked by At

I am trying to create a TransferRepresentation with UTType.calendarEvent to make a struct Transferable and usable in a ShareLink

ShareLink(item: event, preview: SharePreview(event.name))

I tried:

  1. Creating a VCalendar-String and converting it to Data
struct Event: Transferable, ... {
    ...
    let uuid: String
    let name: String
    
    var isoDate: String { ... }

    ...
    
    static var transferRepresentation: some TransferRepresentation {
        DataRepresentation(exportedContentType: .calendarEvent) { event in
            return "BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nUID:\(event.uuid)\nDTSTAMP:\(event.isoDate)\nDTSTART:\(event.isoDate)\nDTEND:\(event.isoDate)\nSUMMARY:\(event.name)\nEND:VEVENT\nEND:VCALENDAR".data(using: .utf8) ?? Data()
        }
    }
}

isoDate is in the format yyyymmddThhmmssZ The ShareLink works, but only shows AirDrop and trying to share via AirDrop always fails. But if I change the exportedContentType to UTType.plainText and rename the exported .txt file to .ics that File works and can be imported in the Calendar.

  1. Creating an EKEvent and converting it to Data
struct Event: Transferable, ... {
    ...
    let uuid: String
    let name: String
    
    var isoDate: String { ... }

    ...
    
    static var transferRepresentation: some TransferRepresentation {
        DataRepresentation(exportedContentType: .calendarEvent) { event in
            let ekevent = EKEvent()
            ...
            return ...
        }
    }
}

But neither ekevent as Data nor Data(ekevent) works

  1. Directly using an EKEvent in the ShareLink, but EKEvent is not Transferable
0

There are 0 answers