Created
August 13, 2015 19:00
-
-
Save MACastro987/303870cb4b137938cea9 to your computer and use it in GitHub Desktop.
Handle AlertViewController actions
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)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { | |
NSString *alertTitle = nil; | |
NSString *alertMessage = nil; | |
NSString *alertOkButtonText = @"Ok"; | |
switch (result) { | |
case MFMailComposeResultSent:{ | |
alertTitle = @"Message Sent"; | |
alertMessage = @"Your message has been sent"; | |
break; | |
} | |
case MFMailComposeResultSaved:{ | |
alertTitle = @"Message Saved"; | |
alertMessage = @"Your message has been saved"; | |
break; | |
} | |
case MFMailComposeResultCancelled:{ | |
alertTitle = @"Message Cancelled"; | |
alertMessage = @"Your message has been cancelled"; | |
break;} | |
case MFMailComposeResultFailed:{ | |
alertTitle = @"Message Failed"; | |
alertMessage = @"Your message could not be sent"; | |
break; | |
} | |
} | |
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:alertTitle | |
message:alertMessage | |
preferredStyle:UIAlertControllerStyleAlert]; | |
//We add buttons to the alert controller by creating UIAlertActions: | |
UIAlertAction *actionOk = [UIAlertAction actionWithTitle:alertOkButtonText | |
style:UIAlertActionStyleDefault | |
handler:^(UIAlertAction *action) { | |
[alertController dismissViewControllerAnimated:YES completion:nil]; | |
}]; //You can use a block here to handle a press on this button | |
[alertController addAction:actionOk]; | |
[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