Files
iOS/Sources/Shared/Intents/SendLocationIntentHandler.swift
Bruno Pantaleão 0008727ff3 WIP
2026-06-15 09:36:28 +02:00

44 lines
1.5 KiB
Swift

import CoreLocation
import Foundation
import Intents
import PromiseKit
#if canImport(UIKit)
import UIKit
#else
import AppKit
#endif
class SendLocationIntentHandler: NSObject, SendLocationIntentHandling {
func resolveLocation(
for intent: SendLocationIntent,
with completion: @escaping (INPlacemarkResolutionResult) -> Void
) {
if let loc = intent.location {
Current.Log.info("using provided \(loc)")
completion(.success(with: loc))
} else {
Current.Log.info("requesting a value")
completion(.needsValue())
}
}
func handle(intent: SendLocationIntent, completion: @escaping (SendLocationIntentResponse) -> Void) {
Current.Log.verbose("Handling send location")
when(fulfilled: Current.apis.map { api in
api.SubmitLocation(updateType: .Siri, location: intent.location?.location, zone: nil)
}).done { _ in
Current.Log.verbose("Successfully submitted location")
let resp = SendLocationIntentResponse(code: .success, userActivity: nil)
resp.location = intent.location
completion(resp)
}.catch { error in
Current.Log.error("Error sending location during Siri Shortcut call: \(error)")
let resp = SendLocationIntentResponse(code: .failure, userActivity: nil)
resp.error = "Error sending location during Siri Shortcut call: \(error.localizedDescription)"
completion(resp)
}
}
}