Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.