Created
July 29, 2014 03:07
-
-
Save ruandao/8021b4e6683c5f564300 to your computer and use it in GitHub Desktop.
mfmessage send message
This file contains hidden or 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
| - (void)showEmail:(NSString*)file { | |
| NSString *emailTitle = @"Great Photo and Doc"; | |
| NSString *messageBody = @"Hey, check this out!"; | |
| NSArray *toRecipents = [NSArray arrayWithObject:@"support@appcoda.com"]; | |
| MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; | |
| mc.mailComposeDelegate = self; | |
| [mc setSubject:emailTitle]; | |
| [mc setMessageBody:messageBody isHTML:NO]; | |
| [mc setToRecipients:toRecipents]; | |
| // Determine the file name and extension | |
| NSArray *filepart = [file componentsSeparatedByString:@"."]; | |
| NSString *filename = [filepart objectAtIndex:0]; | |
| NSString *extension = [filepart objectAtIndex:1]; | |
| // Get the resource path and read the file using NSData | |
| NSString *filePath = [[NSBundle mainBundle] pathForResource:filename ofType:extension]; | |
| NSData *fileData = [NSData dataWithContentsOfFile:filePath]; | |
| // Determine the MIME type | |
| NSString *mimeType; | |
| if ([extension isEqualToString:@"jpg"]) { | |
| mimeType = @"image/jpeg"; | |
| } else if ([extension isEqualToString:@"png"]) { | |
| mimeType = @"image/png"; | |
| } else if ([extension isEqualToString:@"doc"]) { | |
| mimeType = @"application/msword"; | |
| } else if ([extension isEqualToString:@"ppt"]) { | |
| mimeType = @"application/vnd.ms-powerpoint"; | |
| } else if ([extension isEqualToString:@"html"]) { | |
| mimeType = @"text/html"; | |
| } else if ([extension isEqualToString:@"pdf"]) { | |
| mimeType = @"application/pdf"; | |
| } | |
| // Add attachment | |
| [mc addAttachmentData:fileData mimeType:mimeType fileName:filename]; | |
| // Present mail view controller on screen | |
| [self presentViewController:mc animated:YES completion:NULL]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment