Last active
June 25, 2016 16:24
-
-
Save mmuszynski/34f878a7947544b5b6e9a096beae9643 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
//Attempting to load the view of a view controller while it is deallocating | |
//is not allowed and may result in undefined behavior (<UIAlertController: 0x7f8ec04a27a0>) | |
//(wait alert is the one that it is complaining about) | |
@IBAction func addLandmarkWithSelectedType() { | |
let waitAlert = UIAlertController(title: "Waiting for accuracy", message: "Holding until the accuracy improves", preferredStyle: .Alert) | |
let timeoutAlert = UIAlertController(title: "Location Manager Error!", message: "Location manager was not able to provide the necessary accuracy", preferredStyle: .Alert) | |
let cancelTimeoutAlert = { (action: UIAlertAction) in self.dismissViewControllerAnimated(true, completion: nil) } | |
timeoutAlert.addAction(UIAlertAction(title: "Drat", style: .Cancel, handler: cancelTimeoutAlert)) | |
let showTimeoutAlert = { | |
self.presentViewController(timeoutAlert, animated: true, completion: nil) | |
} | |
let beginAddingLandmark = { | |
if self.currentPickerType.isPointLandmark() { | |
do { | |
try self.addPointLandmark(self.currentPickerType) | |
} catch { | |
} | |
} else { | |
} | |
} | |
let completionHandler = { (timeout: Bool) in | |
self.dismissViewControllerAnimated(true, completion: timeout ? showTimeoutAlert : beginAddingLandmark) | |
} | |
//only run the wait block if it is necessary | |
if currentLocation?.horizontalAccuracy > desiredAccuracy { | |
self.presentViewController(waitAlert, animated: true, completion: nil) | |
waitFor(accuracy: desiredAccuracy, withTimeout: 5.0, completion: completionHandler) | |
} else { | |
beginAddingLandmark() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment