Last active
August 29, 2015 14:14
-
-
Save blixt/52d001ffc9e1069c6d11 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
- (void)alertWithTitle:(NSString *)title | |
message:(NSString *)message | |
close:(NSString *)closeText | |
action:(NSString *)actionText | |
then:(void (^)(void))block | |
{ | |
if ([UIAlertController class]) { | |
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title | |
message:message | |
preferredStyle:UIAlertControllerStyleAlert]; | |
if (closeText) { | |
[alert addAction:[UIAlertAction actionWithTitle:closeText style:UIAlertActionStyleCancel handler:nil]]; | |
} | |
if (actionText) { | |
[alert addAction:[UIAlertAction actionWithTitle:closeText style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { | |
if (block) block(); | |
}]]; | |
} | |
[self presentViewController:alert animated:YES completion:nil]; | |
} else { | |
AlertViewCallback *callback = nil; | |
if (block) { | |
callback = [AlertViewCallback callback:block]; | |
} | |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title | |
message:message | |
delegate:callback | |
cancelButtonTitle:closeText | |
otherButtonTitles:nil]; | |
if (actionText) { | |
[alert addButtonWithTitle:actionText]; | |
} | |
[alert show]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment