This gist provides a simple example of how a UIAlertController can be used to obtain and provide visit feedback.
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
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