Sharing event

This commit is contained in:
Selim Mustafaev 2024-12-20 21:56:45 +03:00
parent 5cc4ca02be
commit 2481045a9c
2 changed files with 8 additions and 4 deletions

View File

@ -129,6 +129,10 @@ struct EventsScreen: View {
} label: { } label: {
Label("Open in Maps", systemImage: "map") Label("Open in Maps", systemImage: "map")
} }
if let link = viewModel.getMapLink(for: event) {
ShareLink(item: link)
}
} }
} }
} }

View File

@ -132,9 +132,9 @@ class EventsViewModel: ACHudContainer {
} }
} }
func getMapLink(for event: VehicleEventDto) -> URL? { func getMapLink(for event: EventModel) -> URL? {
var urlString = "http://maps.apple.com/?sll=\(event.latitude),\(event.longitude)" var urlString = "http://maps.apple.com/?sll=\(event.coordinate.latitude),\(event.coordinate.longitude)"
if let address = event.address?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) { if let address = event.address.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
urlString = urlString + "&address=" + address urlString = urlString + "&address=" + address
} }
return URL(string: urlString) return URL(string: urlString)
@ -146,7 +146,7 @@ class EventsViewModel: ACHudContainer {
} }
let sharedData: [String: Any?] = [ let sharedData: [String: Any?] = [
UTType.url.identifier: getMapLink(for: eventDto), UTType.url.identifier: getMapLink(for: event),
UTType.vehicleEvent.identifier: try? JSONEncoder().encode(eventDto) UTType.vehicleEvent.identifier: try? JSONEncoder().encode(eventDto)
] ]