|
#import "mailman.h" |
|
|
|
@implementation MailMan |
|
|
|
- (id)initWithParentVC:(UIViewController *)vc |
|
{ |
|
self = [super init]; |
|
if(self) { |
|
NSLog(@"_init: %@", self); |
|
self.vc = vc; |
|
} |
|
return self; |
|
} |
|
|
|
- (void)emailWithSubject: (NSString *)subject andText:(NSString*)text { |
|
[self emailWithSubject:subject andMessage:text isHTML:NO]; |
|
} |
|
|
|
- (void)emailWithSubject: (NSString *)subject andHTML:(NSString*)html { |
|
[self emailWithSubject:subject andMessage:html isHTML:YES]; |
|
} |
|
|
|
- (void)emailWithSubject: (NSString *)subject andMessage:(NSString*)string isHTML:(BOOL)isHTML |
|
{ |
|
if ([MFMailComposeViewController canSendMail]) { |
|
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init]; |
|
mailViewController.mailComposeDelegate = self; |
|
[mailViewController setSubject:subject]; |
|
[mailViewController setMessageBody:string isHTML:isHTML]; |
|
|
|
[self.vc presentViewController:mailViewController animated:YES completion:nil]; |
|
} else { |
|
NSLog(@"Device is unable to send email in its current state."); |
|
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Email Account" message:@"You have not configured this device for sending email." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; |
|
[alert show]; |
|
} |
|
} |
|
|
|
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { |
|
|
|
UIAlertView *alert; |
|
switch (result) { |
|
case MFMailComposeResultCancelled: |
|
NSLog(@"Mail Cancelled"); |
|
alert = [[UIAlertView alloc] initWithTitle:@"Email Feedback:" message:@"Mail Cancelled." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; |
|
[alert show]; |
|
break; |
|
case MFMailComposeResultSaved: |
|
NSLog(@"Mail Saved"); |
|
alert = [[UIAlertView alloc] initWithTitle:@"Email Feedback:" message:@"Mail Saved." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; |
|
[alert show]; |
|
break; |
|
case MFMailComposeResultSent: |
|
NSLog(@"Sent Mail"); |
|
alert = [[UIAlertView alloc] initWithTitle:@"Email Feedback:" message:@"Sent Mail." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; |
|
[alert show]; |
|
break; |
|
case MFMailComposeResultFailed: |
|
NSLog(@"Mail Failed"); |
|
NSLog(@"%@", error.localizedDescription); |
|
alert = [[UIAlertView alloc] initWithTitle:@"Email Feedback:" message:[NSString stringWithFormat:@"Mail Failed: %@", error.localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; |
|
[alert show]; |
|
break; |
|
default: |
|
break; |
|
} |
|
[self.vc dismissViewControllerAnimated:YES completion:nil]; |
|
} |
|
|
|
@end |