Skip to content

Instantly share code, notes, and snippets.

@vixentael
Created May 22, 2015 13:40
Show Gist options
  • Select an option

  • Save vixentael/bdbca4a5532940066e9f to your computer and use it in GitHub Desktop.

Select an option

Save vixentael/bdbca4a5532940066e9f to your computer and use it in GitHub Desktop.
show mail controller from any VC
#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