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:
- 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.
- Creating an
EKEventand converting it toData
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
- Directly using an
EKEventin theShareLink, butEKEventis notTransferable