Skip to content

Commit

Permalink
Update action sheet to iOS 8+ alert controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Seward committed Sep 16, 2015
1 parent ebb5121 commit 1307d45
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions GKClasses/GKImagePicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,48 @@ - (void)showActionSheetOnViewController:(UIViewController *)viewController onPop
{
self.presentingViewController = viewController;
self.popoverView = popoverView;
NSString *fromCameraString = NSLocalizedString(@"Image from Camera", @"Image from Camera");
NSString *fromLibraryString = NSLocalizedString(@"Image from Library", @"Image from Library");
NSString *cancelTitle = NSLocalizedString(@"Cancel", @"Cancel");

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:(id)self
cancelButtonTitle:NSLocalizedString(@"Cancel", @"Cancel")
destructiveButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"Image from Camera", @"Image from Camera"), NSLocalizedString(@"Image from Library", @"Image from Library"), nil];
actionSheet.delegate = self;

if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
[actionSheet showFromRect:self.popoverView.frame inView:self.presentingViewController.view animated:YES];
} else {
if (self.presentingViewController.navigationController.toolbar) {
[actionSheet showFromToolbar:self.presentingViewController.navigationController.toolbar];
if (NSFoundationVersionNumber >= NSFoundationVersionNumber_iOS_8_0) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

}];

UIAlertAction *fromCameraAction = [UIAlertAction actionWithTitle:fromCameraString style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self showCameraImagePicker];
}];

UIAlertAction *fromLibraryAction = [UIAlertAction actionWithTitle:fromLibraryString style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self showGalleryImagePicker];
}];

[alertController addAction:cancelAction];
[alertController addAction:fromCameraAction];
[alertController addAction:fromLibraryAction];

[viewController presentViewController:alertController animated:YES completion:^{

}];
}
else {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:(id)self
cancelButtonTitle:NSLocalizedString(@"Cancel", @"Cancel")
destructiveButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"Image from Camera", @"Image from Camera"), NSLocalizedString(@"Image from Library", @"Image from Library"), nil];
actionSheet.delegate = self;

if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
[actionSheet showFromRect:self.popoverView.frame inView:self.presentingViewController.view animated:YES];
} else {
[actionSheet showInView:self.presentingViewController.view];
if (self.presentingViewController.navigationController.toolbar) {
[actionSheet showFromToolbar:self.presentingViewController.navigationController.toolbar];
} else {
[actionSheet showInView:self.presentingViewController.view];
}
}
}
}
Expand Down

0 comments on commit 1307d45

Please sign in to comment.