Monday, May 28, 2012

Send Email with attachment in iPhone

We need MessageUI framework to send email. Sending Email can not be tested using iPhone simulator. The reason is simulator does not include a mail app. The application should be installed in actual device and tested. In simulator, it displays a successful message that email has been sent but it just an indicator that no other problem with source code.

[sourcecode language="objc"]

NSData *audioFile = [[NSData alloc]initWithContentsOfURL:temporaryRecFile];

MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc]init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Greeting Message"];
NSArray *toReceipients = [NSArray arrayWithObjects:@"recepient_mail_address", nil];
[mailer setToRecipients:toReceipients];
[mailer addAttachmentData:audioFile mimeType:@"audio/caf" fileName:@"VoiceFile.caf"];
[mailer setMessageBody:@"My greetings for you" isHTML:NO];

[self presentModalViewController:mailer animated:YES];
[mailer release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Failure" message:@"Device does not support" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];


[/sourcecode]

No comments:

Post a Comment

How to enable CORS in Laravel 5

https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...