Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
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