Skip to content

Instantly share code, notes, and snippets.

@Cellane
Last active September 15, 2015 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cellane/f1c7243b24c42e41345b to your computer and use it in GitHub Desktop.
Save Cellane/f1c7243b24c42e41345b to your computer and use it in GitHub Desktop.
- (IBAction)obtainCoordinates:(UIButton *)sender {
sender.enabled = NO;
[CLLocationManager promise].then(^(CLLocation *location) {
self.fromTextField.text = [NSString stringWithFormat:@"GPS: %f,%f", location.coordinate.latitude, location.coordinate.longitude];
}).catch(^(NSError *error) {
[self presentGPSError:error];
}).finally(^{
sender.enabled = YES;
});
}
- (void)presentGPSError:(NSError *)error {
if (error.code == 1) {
[self presentViewController:[AINContext current].settingsAlertController animated:YES completion:nil];
} else {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Chyba GPS" message:@"Nepodařilo se zjistit současnou polohu, zkuste to prosím později." preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Rozumím" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment