Created
May 22, 2015 13:40
-
-
Save vixentael/bdbca4a5532940066e9f to your computer and use it in GitHub Desktop.
show mail controller from any VC
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
| #import <MessageUI/MessageUI.h> | |
| - (void)showContactUsFromScreen:(UIViewController *)controller completion:(SFActionBlock)completion { | |
| if ( [MFMailComposeViewController canSendMail] ) { | |
| controller.view.userInteractionEnabled = NO; | |
| __weak UIViewController * weakController = controller; | |
| MFMailComposeViewController * mailComposeViewController = [[MFMailComposeViewController alloc] init]; | |
| mailComposeViewController.mailComposeDelegate = self; | |
| [mailComposeViewController setSubject:NSLocalizedString(@"ContactUs.Subject", @"")]; | |
| [mailComposeViewController setToRecipients:@[kContactUsEmail]]; | |
| [mailComposeViewController.navigationBar setBarTintColor:[THStyles defaultBlueBackgroundColor]]; | |
| [mailComposeViewController.navigationBar setTintColor:[THStyles defaultWhiteColor]]; | |
| // Handle Mail Composer | |
| [[[[self rac_signalForSelector:@selector(mailComposeController:didFinishWithResult:error:)fromProtocol:@protocol(MFMailComposeViewControllerDelegate)] take:1] | |
| reduceEach:^id(MFMailComposeViewController * mailController, NSNumber * result, NSError * error){ | |
| return result; | |
| }] | |
| subscribeNext:^(id result) { | |
| weakController.view.userInteractionEnabled = YES; | |
| [weakController dismissViewControllerAnimated:YES completion:nil]; | |
| if (completion) { | |
| completion(); | |
| } | |
| }]; | |
| [controller presentViewController:mailComposeViewController animated:YES completion:nil]; | |
| } else { | |
| [[UIPasteboard generalPasteboard] setString:kContactUsEmail]; | |
| [SVProgressHUD showErrorWithStatus:NSLocalizedString(@"ContactUs.Error", @"")]; | |
| } | |
| [SFStatisticsManager trackEvent:kStatsEventSettingsContactUs params:nil]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment