Loading...

iPhone Programming: In-App Email - How to attach files

10,644 views

Loading...

Loading...

Transcript

The interactive transcript could not be loaded.

Loading...

Loading...

Rating is available when the video has been rented.
This feature is not available right now. Please try again later.
Uploaded on Sep 9, 2011

A tutorial teaching you how to attach .png and .jpeg images to your in-app emails.

Main code used:

-(IBAction) openEmail:(id)sender
{ //Open MFMail and set preferences
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
[mailComposer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[mailComposer setToRecipients:[NSArray arrayWithObjects:@"failcakeapps@yahoo.co.uk", nil]];
[mailComposer setSubject:@"Awesome Image"];
[mailComposer setMessageBody:@"Hey,\n\nCheck out this awesome image!\n\n" isHTML:NO]; [mailComposer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; if ([sender tag] == 0) { UIImage *lion = [UIImage imageNamed:@"01-Mac-OS-X-Lion.jpg"]; NSData *lionData = UIImageJPEGRepresentation(lion, 1); [mailComposer addAttachmentData:lionData mimeType:@"image/jpeg" fileName:@"01-Mac-OS-X-Lion.jpg"]; } else if ([sender tag] == 1) { UIImage *xcode = [UIImage imageNamed:@"Xcode_icon.png"]; NSData *xcodeData = UIImagePNGRepresentation(xcode); [mailComposer addAttachmentData:xcodeData mimeType:@"image/png" fileName:@"Xcode_icon.png"]; } [self presentModalViewController:mailComposer animated:YES]; [mailComposer release]; } else { [mailComposer release]; }
}

//Dismiss MFMail
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { if (error) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"Error %@", [error description]] delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; [alert show]; [alert release]; [self dismissModalViewControllerAnimated:YES]; } [self dismissModalViewControllerAnimated:YES];
}

MIME Type Wiki: http://en.wikipedia.org/wiki/MIME
List of MIME Types: http://en.wikipedia.org/wiki/Internet...

Twitter: http://twitter.com/failcakeapps
Apple Developer Center: http://developer.apple.com/devcenter/...
Website: http://failcake.webs.com/
Channel: http://youtube.com/milmersxcode

Loading...

Advertisement
When autoplay is enabled, a suggested video will automatically play next.

Up next


to add this to Watch Later

Add to

Loading playlists...