Last active
December 9, 2018 06:35
-
-
Save erkanyildiz/454874e10719082120ab219162827efa to your computer and use it in GitHub Desktop.
Support mail composer with activity indicator
This file contains 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
// erkanyildiz | |
// 20170828-2105+0900 | |
// | |
// EYSupportMailComposer.h | |
#import <Foundation/Foundation.h> | |
@interface EYSupportMailComposer : NSObject | |
+ (void)presentMailComposerOnViewController:(UIViewController *)viewController withEmail:(NSString *)email; | |
@end |
This file contains 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
// 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