【发布时间】:2018-02-03 12:42:44
【问题描述】:
您可以在下面找到我用来向用户日历添加条目的代码。
我想知道如何在条目中添加位置标记 - 我找到了event.structuredLocation 属性。
如何在条目中添加 (lat/lon) - 坐标?使用 CLLocationCoordinate2D(lat:, lon:) 不起作用。
func addReminder() {
let eventStore : EKEventStore = EKEventStore()
let event:EKEvent = EKEvent(eventStore: eventStore)
event.title = "myevent"
event.startDate = Date()
event.endDate = Date()
event.calendar = eventStore.defaultCalendarForNewEvents
event.structuredLocation = CLLocationCoordinate2D(latitude: 1.0, longitude: 2.0) // not working
do {
try eventStore.save(event, span: .thisEvent)
} catch let error as NSError {
print("error : \(error)")
}
}
编辑 (1) :我确定我必须使用 EKStructuredLocation。但我也不知道如何实现这一点? (EKStructuredLocation(mapItem: MKMapItem))
编辑(2):
let map = MKMapItem()
map.name = "myplace"
map.placemark.coordinate.latitude = 10.0 // error
map.placemark.coordinate.longitude = 10.0 // error
编辑(3):
是否可以在 event.notes 属性中添加粗体?
event.notes = "default text and bold text" // like html
//"default text and <b>bold text</b>"
任何帮助将不胜感激:)
【问题讨论】:
-
我为您提供了编辑 2 的替代方法,您可以使用 CLLocation 而不是 MKMapItem 创建结构化位置。至于您关于包含粗体文本的注释的问题,答案似乎是否定的。 notes 属性是
String,而不是AttributedString,我根本看不到任何属性字符串属性。此外,日历应用似乎不支持备注字段中的样式文本。