Skip to content

Instantly share code, notes, and snippets.

@erkanyildiz
Last active December 9, 2018 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erkanyildiz/454874e10719082120ab219162827efa to your computer and use it in GitHub Desktop.
Save erkanyildiz/454874e10719082120ab219162827efa to your computer and use it in GitHub Desktop.
Support mail composer with activity indicator
// erkanyildiz
// 20170828-2105+0900
//
// EYSupportMailComposer.h
#import <Foundation/Foundation.h>
@interface EYSupportMailComposer : NSObject
+ (void)presentMailComposerOnViewController:(UIViewController *)viewController withEmail:(NSString *)email;
@end
// erkanyildiz
// 20170828-2105+0900
//
// EYSupportMailComposer.h
#import "EYSupportMailComposer.h"
#import <MessageUI/MessageUI.h>
#import <sys/utsname.h>
#import "EYUtils.h"
@interface EYSupportMailComposer () <MFMailComposeViewControllerDelegate>
@end
@implementation EYSupportMailComposer
static EYSupportMailComposer *delegateInstance;
+ (void)presentMailComposerOnViewController:(UIViewController *)viewController withEmail:(NSString *)email
{
MFMailComposeViewController *mc = MFMailComposeViewController.new;
if(!mc)
return;
NSString* appName = [NSBundle.mainBundle objectForInfoDictionaryKey:(NSString*)kCFBundleNameKey];
NSString* appVersion = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString* osVersion = UIDevice.currentDevice.systemVersion;
struct utsname deviceInfo;
uname(&deviceInfo);
NSString* deviceModel = [NSString stringWithCString:deviceInfo.machine encoding:NSUTF8StringEncoding];
NSString* systemInfo = [NSString stringWithFormat:@"\n\n"
"---System Info---\n"
"App Name: %@\n"
"App Version: %@\n"
"iOS Version: %@\n"
"Device Model: %@\n"
"Locale ID: %@",
appName,
appVersion,
osVersion,
deviceModel,
NSLocale.currentLocale.localeIdentifier];
[mc setSubject: [NSString stringWithFormat:@"Feedback %@ %@", appName, appVersion]];
[mc setToRecipients:@[email]];
[mc setMessageBody:systemInfo isHTML:NO];
delegateInstance = EYSupportMailComposer.new;
[mc setMailComposeDelegate:delegateInstance];
[viewController showActivityIndicator];
[viewController presentViewController:mc animated:YES completion:^
{
[viewController hideActivityIndicator];
}];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error
{
[controller dismissViewControllerAnimated:YES completion:nil];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment