Instantly share code, notes, and snippets.

Embed
What would you like to do?
private func performSiriDonation(with ride: inout Ride) -> BookRideIntent? {
// Y aquí es donde *donamos* el shortcut a Siri.
// De esta manera Siri aprende sobre nuestras costumbres
// en la app para luego poder hacer las recomendaciones
let shortcut = BookRideIntent()
switch ride.paymentMethod {
case .applePay:
shortcut.payment = INPaymentMethod.applePay()
case .paypal:
shortcut.payment = INPaymentMethod(type: .checking, name: "PayPal", identificationHint: nil, icon: nil)
case .visa:
shortcut.payment = INPaymentMethod(type: .credit, name: "Visa", identificationHint: nil, icon: nil)
}
shortcut.origin = CLPlacemark(location: ride.from.location, name: "Origen", postalAddress: nil)
shortcut.destination = CLPlacemark(location: ride.destination.location, name: "Destino", postalAddress: nil)
shortcut.car = INObject(identifier: ride.car.rawValue, display: ride.car.localizedString)
if let image = UIImage(named: "Shortcut"), let data = image.pngData() {
shortcut.setImage(INImage(imageData: data), forParameterNamed: "destination")
}
shortcut.suggestedInvocationPhrase = "Pide un coche"
ride.siriShortcutIdentifier = shortcut.identifier
let interaction = INInteraction(intent: shortcut, response: nil)
interaction.donate() { (error: Error?) -> Void in
if let error = error {
os_log("%@", error.localizedDescription)
} else {
os_log("Shortcut donated")
}
}
return shortcut
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment