I have a custom url scheme added to the iOS calendar event. Is there any way to change the text of the url scheme from being appName:// to something more optically familiar (i.e. click here or https://appName.com).
func addCalendar() {
var eventStore = EKEventStore()
var calendar: EKCalendar?
let calendars = eventStore.calendars(for: .event)
let calendarTitle = "AppName"
let predicate = NSPredicate(format: "title matches %@", calendarTitle)
let filtered = (calendars as NSArray).filtered(using: predicate)
if filtered.count != 0, let filteredCalendar = filtered.first as? EKCalendar {
calendar = filteredCalendar
addEvent(with: eventStore, calendar)
} else {
calendar = EKCalendar(for: .event, eventStore: eventStore)
calendar?.title = "AppName"
calendar?.source = eventStore.defaultCalendarForNewEvents?.source
guard let setCalendar = calendar else { return }
do { try eventStore.saveCalendar(setCalendar, commit: true) }
catch { print("Failed to save calendar") }
addEvent(with: eventStore, calendar)
}
}
func addEvent(with eventStore: EKEventStore, _ calendar: EKCalendar?) {
guard let calendar = calendar else { return }
if let calendarForEvent = eventStore.calendar(withIdentifier: calendar.calendarIdentifier) {
let newEvent = EKEvent(eventStore: eventStore)
newEvent.calendar = calendarForEvent
newEvent.title = "Some Title"
newEvent.startDate = Date()
newEvent.endDate = Date()
newEvent.notes = "Some notes"
newEvent.url = URL(string: "appName://")
do { try eventStore.save(newEvent, span: .thisEvent, commit: true) }
catch { print("Could not save event to user's calendar.") }
}
}
question from:
https://stackoverflow.com/questions/65853747/change-text-of-custom-url-scheme 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…