-
-
Save fitomad/04a2f55cab0a538fd378aca4a87c27f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Preparamos el UI del Intent en función de su estado | |
*/ | |
internal func configureView(for parameters: Set, of interaction: INInteraction, interactiveBehavior: INUIInteractiveBehavior, context: INUIHostedViewContext, completion: @escaping (Bool, Set, CGSize) -> Void) { | |
// Fase de confirmación | |
if interaction.intentHandlingStatus == .ready { | |
if let intent = interaction.intent as? BookRideIntent { | |
var mensaje = "Coche con destino a " | |
if let destino = intent.destination?.name { | |
mensaje += destino | |
} | |
if let car = intent.car, let identifier = car.identifier, let carType = CarType(rawValue: identifier) { | |
mensaje += " en un \(carType.localizedString) " | |
} | |
if let payment = intent.payment, let paymentName = payment.name { | |
mensaje += "pagando con \(paymentName)" | |
} | |
self.labelArrivalAdvice.text = mensaje | |
self.labelArrivalTime.text = "" | |
} | |
completion(true, parameters, CGSize(width: 320.0, height: 100.0)) | |
} | |
// Fase de "éxito". Ocurre tras darle al botón "Reservar" | |
if interaction.intentHandlingStatus == .success { | |
if let response = interaction.intentResponse as? BookRideIntentResponse { | |
self.labelArrivalAdvice.text = "Dependiendo del tráfico puedo haber algún retraso. Gracias por tu paciencia." | |
self.labelRideAdvice.text = "El precio incluye el 21% de IVA junto con una botella de agua." | |
if let driverName = response.driverName { | |
self.labelDriverName.text = driverName | |
} | |
if let arrivalTime = response.arrivalTime { | |
self.labelArrivalTime.text = "\(arrivalTime) min" | |
} | |
if let imageURL = response.driverImageURL { | |
self.imageDriver.image = UIImage(named: imageURL) | |
} | |
completion(true, parameters, self.desiredSize) | |
} | |
else { | |
completion(true, parameters, CGSize.zero) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment