Skip to content

Instantly share code, notes, and snippets.

@kyleadrian
Last active February 7, 2020 18:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
This gist provides a simple example of how a UIAlertController can be used to obtain and provide visit feedback.
extension UIAlertController {
static func presentFeedbackAlertControllerForVisit(_ visit: Visit, controller: UIViewController, dismiss: (() -> Void)? = nil) {
let alertController = UIAlertController(title: "Provide feedback:", message: visit.description, preferredStyle: .actionSheet)
if let pilgrimVisitId = visit.pilgrimVisitId, let feedbackProvider = PilgrimManager.shared().feedbackProvider {
// Correct Venue
let correctAction = UIAlertAction(title: "Confirm", style: .default) { (action) -> Void in
feedbackProvider.leaveVisitFeedback(.confirm, visitId: pilgrimVisitId, actualVenueId: nil, completion: nil)
}
// False Stop
let falseStopAction = UIAlertAction(title: "False stop", style: .default) { (action) -> Void in
feedbackProvider.leaveVisitFeedback(.falseStop, visitId: pilgrimVisitId, actualVenueId: nil, completion: nil)
}
// Wrong Venue
let wrongVenueAction = UIAlertAction(title: "Wrong venue", style: .default) { (action) -> Void in
// TODO: If selected, you should probably add an option for users to select the accurate venue
// and send in the actual venue ID.
feedbackProvider.leaveVisitFeedback(.wrongVenue, visitId: pilgrimVisitId, actualVenueId: nil, completion: nil)
}
// Deny Venue
let denyAction = UIAlertAction(title: "Deny", style: .default) { (action) -> Void in
feedbackProvider.leaveVisitFeedback(.deny, visitId: pilgrimVisitId, actualVenueId: nil, completion: nil)
}
// Add all actions
alertController.addAction(correctAction)
alertController.addAction(falseStopAction)
alertController.addAction(wrongVenueAction)
alertController.addAction(denyAction)
}
// Default Cancel
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(cancelAction)
controller.present(alertController, animated: true, completion: dismiss)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment