Skip to content

Instantly share code, notes, and snippets.

@MACastro987
Created August 13, 2015 19:00
Show Gist options
  • Save MACastro987/303870cb4b137938cea9 to your computer and use it in GitHub Desktop.
Save MACastro987/303870cb4b137938cea9 to your computer and use it in GitHub Desktop.
Handle AlertViewController actions
- (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