-
-
Save nesimtunc/9012ac6a28ade9abc122ae596543f042 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; | |
+ (void)presentMailComposerOnViewController:(UIViewController *)viewController withEmail:(NSString *)email withSubject:(NSString*) subject; | |
@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 | |
{ | |
[self presentMailComposerOnViewController:viewController withEmail:email withSubject:nil]; | |
} | |
+ (void)presentMailComposerOnViewController:(UIViewController *)viewController withEmail:(NSString *)email withSubject:(NSString*) subject { | |
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 = FS(@"\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); | |
if (!subject) { | |
subject = FS(@"Feedback %@ %@", appName, appVersion); | |
} | |
[mc setSubject:subject]; | |
[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